@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $license_key = self::getSetting('license_key'); |
| 193 | 193 | if( '' === $license_key ) { |
| 194 | 194 | $license_status = 'inactive'; |
| 195 | - } |
|
| 195 | + } |
|
| 196 | 196 | $license_id = empty( $license_key ) ? 'license' : $license_key; |
| 197 | 197 | |
| 198 | 198 | $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'); |
@@ -450,8 +450,8 @@ discard block |
||
| 450 | 450 | type="' . $field['type'] . '" |
| 451 | 451 | name="' . esc_attr( $name ) . '" |
| 452 | 452 | value="' . $value . '" ' . |
| 453 | - implode( ' ', $attributes ) . |
|
| 454 | - ' />'; |
|
| 453 | + implode( ' ', $attributes ) . |
|
| 454 | + ' />'; |
|
| 455 | 455 | |
| 456 | 456 | if ( $echo ) { |
| 457 | 457 | echo $html; |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | array( |
| 677 | 677 | 'label' => _x( 'Permanently Delete', 'Setting: what to do when uninstalling plugin', 'gravityview' ), |
| 678 | 678 | 'value' => 'delete', |
| 679 | - 'tooltip' => sprintf( '<h6>%s</h6><p><span class="howto">%s</span></p><p>%s</p>', __( 'Delete all GravityView content and settings', 'gravityview' ), __( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' ), __( 'When GravityView is uninstalled and deleted, delete all Views, GravityView entry approvals, GravityView-generated entry notes (including approval and entry creator changes), and GravityView plugin settings. No Gravity Forms data will be touched.', 'gravityview' ) ), |
|
| 679 | + 'tooltip' => sprintf( '<h6>%s</h6><p><span class="howto">%s</span></p><p>%s</p>', __( 'Delete all GravityView content and settings', 'gravityview' ), __( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' ), __( 'When GravityView is uninstalled and deleted, delete all Views, GravityView entry approvals, GravityView-generated entry notes (including approval and entry creator changes), and GravityView plugin settings. No Gravity Forms data will be touched.', 'gravityview' ) ), |
|
| 680 | 680 | ), |
| 681 | 681 | ), |
| 682 | 682 | 'description' => sprintf( __( 'Should GravityView content and entry approval status be removed from the site when the GravityView plugin is deleted?', 'gravityview' ), __( 'Permanently Delete', 'gravityview' ) ), |
@@ -702,36 +702,36 @@ discard block |
||
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | |
| 705 | - $sections = array( |
|
| 706 | - array( |
|
| 707 | - 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
| 708 | - 'fields' => $fields, |
|
| 709 | - ) |
|
| 710 | - ); |
|
| 705 | + $sections = array( |
|
| 706 | + array( |
|
| 707 | + 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
| 708 | + 'fields' => $fields, |
|
| 709 | + ) |
|
| 710 | + ); |
|
| 711 | 711 | |
| 712 | - // custom 'update settings' button |
|
| 713 | - $button = array( |
|
| 714 | - 'class' => 'button button-primary button-hero', |
|
| 715 | - 'type' => 'save', |
|
| 716 | - ); |
|
| 712 | + // custom 'update settings' button |
|
| 713 | + $button = array( |
|
| 714 | + 'class' => 'button button-primary button-hero', |
|
| 715 | + 'type' => 'save', |
|
| 716 | + ); |
|
| 717 | 717 | |
| 718 | 718 | if( $disabled_attribute ) { |
| 719 | 719 | $button['disabled'] = $disabled_attribute; |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
| 723 | - /** |
|
| 724 | - * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page |
|
| 725 | - * Extensions can tap in here to insert their own section and settings. |
|
| 726 | - * <code> |
|
| 727 | - * $sections[] = array( |
|
| 728 | - * 'title' => __( 'GravityView My Extension Settings', 'gravityview' ), |
|
| 729 | - * 'fields' => $settings, |
|
| 730 | - * ); |
|
| 731 | - * </code> |
|
| 732 | - * @param array $extension_settings Empty array, ready for extension settings! |
|
| 733 | - */ |
|
| 734 | - $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() ); |
|
| 723 | + /** |
|
| 724 | + * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page |
|
| 725 | + * Extensions can tap in here to insert their own section and settings. |
|
| 726 | + * <code> |
|
| 727 | + * $sections[] = array( |
|
| 728 | + * 'title' => __( 'GravityView My Extension Settings', 'gravityview' ), |
|
| 729 | + * 'fields' => $settings, |
|
| 730 | + * ); |
|
| 731 | + * </code> |
|
| 732 | + * @param array $extension_settings Empty array, ready for extension settings! |
|
| 733 | + */ |
|
| 734 | + $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() ); |
|
| 735 | 735 | |
| 736 | 736 | // If there are extensions, add a section for them |
| 737 | 737 | if ( ! empty( $extension_sections ) ) { |
@@ -744,13 +744,13 @@ discard block |
||
| 744 | 744 | } |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - $k = count( $extension_sections ) - 1 ; |
|
| 748 | - $extension_sections[ $k ]['fields'][] = $button; |
|
| 747 | + $k = count( $extension_sections ) - 1 ; |
|
| 748 | + $extension_sections[ $k ]['fields'][] = $button; |
|
| 749 | 749 | $sections = array_merge( $sections, $extension_sections ); |
| 750 | 750 | } else { |
| 751 | - // add the 'update settings' button to the general section |
|
| 752 | - $sections[0]['fields'][] = $button; |
|
| 753 | - } |
|
| 751 | + // add the 'update settings' button to the general section |
|
| 752 | + $sections[0]['fields'][] = $button; |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | 755 | return $sections; |
| 756 | 756 | } |
@@ -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,42 +184,42 @@ 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_key = self::getSetting('license_key'); |
|
| 193 | - if( '' === $license_key ) { |
|
| 191 | + $license_status = self::getSetting( 'license_key_status' ); |
|
| 192 | + $license_key = self::getSetting( 'license_key' ); |
|
| 193 | + if ( '' === $license_key ) { |
|
| 194 | 194 | $license_status = 'inactive'; |
| 195 | 195 | } |
| 196 | 196 | $license_id = empty( $license_key ) ? 'license' : $license_key; |
| 197 | 197 | |
| 198 | - $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'); |
|
| 198 | + $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' ); |
|
| 199 | 199 | |
| 200 | 200 | /** |
| 201 | 201 | * I wanted to remove the period from after the buttons in the string, |
| 202 | 202 | * but didn't want to mess up the translation strings for the translators. |
| 203 | 203 | */ |
| 204 | 204 | $message = mb_substr( $message, 0, mb_strlen( $message ) - 1 ); |
| 205 | - $title = __('Inactive License', 'gravityview'); |
|
| 205 | + $title = __( 'Inactive License', 'gravityview' ); |
|
| 206 | 206 | $status = ''; |
| 207 | 207 | $update_below = false; |
| 208 | 208 | $primary_button_link = admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ); |
| 209 | 209 | switch ( $license_status ) { |
| 210 | 210 | /** @since 1.17 */ |
| 211 | 211 | case 'expired': |
| 212 | - $title = __('Expired License', 'gravityview'); |
|
| 212 | + $title = __( 'Expired License', 'gravityview' ); |
|
| 213 | 213 | $status = 'expired'; |
| 214 | - $message = $this->get_license_handler()->strings( 'expired', self::getSetting('license_key_response') ); |
|
| 214 | + $message = $this->get_license_handler()->strings( 'expired', self::getSetting( 'license_key_response' ) ); |
|
| 215 | 215 | break; |
| 216 | 216 | case 'invalid': |
| 217 | - $title = __('Invalid License', 'gravityview'); |
|
| 218 | - $status = __('is invalid', 'gravityview'); |
|
| 217 | + $title = __( 'Invalid License', 'gravityview' ); |
|
| 218 | + $status = __( 'is invalid', 'gravityview' ); |
|
| 219 | 219 | break; |
| 220 | 220 | case 'deactivated': |
| 221 | - $status = __('is inactive', 'gravityview'); |
|
| 222 | - $update_below = __('Activate your license key below.', 'gravityview'); |
|
| 221 | + $status = __( 'is inactive', 'gravityview' ); |
|
| 222 | + $update_below = __( 'Activate your license key below.', 'gravityview' ); |
|
| 223 | 223 | break; |
| 224 | 224 | /** @noinspection PhpMissingBreakStatementInspection */ |
| 225 | 225 | case '': |
@@ -227,27 +227,27 @@ discard block |
||
| 227 | 227 | // break intentionally left blank |
| 228 | 228 | case 'inactive': |
| 229 | 229 | case 'site_inactive': |
| 230 | - $status = __('has not been activated', 'gravityview'); |
|
| 231 | - $update_below = __('Activate your license key below.', 'gravityview'); |
|
| 230 | + $status = __( 'has not been activated', 'gravityview' ); |
|
| 231 | + $update_below = __( 'Activate your license key below.', 'gravityview' ); |
|
| 232 | 232 | break; |
| 233 | 233 | } |
| 234 | - $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice'; |
|
| 234 | + $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content=' . $license_status . '&utm_campaign=Admin%20Notice'; |
|
| 235 | 235 | |
| 236 | 236 | // Show a different notice on settings page for inactive licenses (hide the buttons) |
| 237 | - if( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { |
|
| 237 | + if ( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { |
|
| 238 | 238 | $message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' ); |
| 239 | 239 | } else { |
| 240 | 240 | $message = sprintf( $message, $status, "\n\n" . '<a href="' . esc_url( $primary_button_link ) . '" class="button button-primary">', '</a>', '<a href="' . esc_url( $url ) . '" class="button button-secondary">', '</a>' ); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if( !empty( $status ) ) { |
|
| 243 | + if ( ! empty( $status ) ) { |
|
| 244 | 244 | GravityView_Admin_Notices::add_notice( array( |
| 245 | 245 | 'message' => $message, |
| 246 | 246 | 'class' => 'updated', |
| 247 | 247 | 'title' => $title, |
| 248 | 248 | 'cap' => 'gravityview_edit_settings', |
| 249 | - 'dismiss' => sha1( $license_status.'_'.$license_id ), |
|
| 250 | - )); |
|
| 249 | + 'dismiss' => sha1( $license_status . '_' . $license_id ), |
|
| 250 | + ) ); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | $styles = parent::styles(); |
| 261 | 261 | |
| 262 | - $styles[] = array( |
|
| 262 | + $styles[ ] = array( |
|
| 263 | 263 | 'handle' => 'gravityview_settings', |
| 264 | 264 | 'src' => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ), |
| 265 | 265 | 'version' => GravityView_Plugin::version, |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @return void |
| 283 | 283 | */ |
| 284 | 284 | public function add_network_menu() { |
| 285 | - if( GravityView_Plugin::is_network_activated() ) { |
|
| 285 | + if ( GravityView_Plugin::is_network_activated() ) { |
|
| 286 | 286 | add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' ); |
| 287 | 287 | } |
| 288 | 288 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * If multisite and not network admin, we don't want the settings to show. |
| 300 | 300 | * @since 1.7.6 |
| 301 | 301 | */ |
| 302 | - $show_submenu = !is_multisite() || is_main_site() || !GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); |
|
| 302 | + $show_submenu = ! is_multisite() || is_main_site() || ! GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); |
|
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | 305 | * Override whether to show the Settings menu on a per-blog basis. |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | $show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu ); |
| 310 | 310 | |
| 311 | - if( $show_submenu ) { |
|
| 311 | + if ( $show_submenu ) { |
|
| 312 | 312 | add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) ); |
| 313 | 313 | } |
| 314 | 314 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | /** |
| 340 | 340 | * Backward compatibility with Redux |
| 341 | 341 | */ |
| 342 | - if( $setting_name === 'license' ) { |
|
| 342 | + if ( $setting_name === 'license' ) { |
|
| 343 | 343 | return array( |
| 344 | 344 | 'license' => parent::get_app_setting( 'license_key' ), |
| 345 | 345 | 'status' => parent::get_app_setting( 'license_key_status' ), |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | |
| 404 | 404 | $return = $text . $activation; |
| 405 | 405 | |
| 406 | - if( $echo ) { |
|
| 406 | + if ( $echo ) { |
|
| 407 | 407 | echo $return; |
| 408 | 408 | } |
| 409 | 409 | |
@@ -430,15 +430,15 @@ discard block |
||
| 430 | 430 | */ |
| 431 | 431 | public function settings_submit( $field, $echo = true ) { |
| 432 | 432 | |
| 433 | - $field['type'] = ( isset($field['type']) && in_array( $field['type'], array('submit','reset','button') ) ) ? $field['type'] : 'submit'; |
|
| 433 | + $field[ 'type' ] = ( isset( $field[ 'type' ] ) && in_array( $field[ 'type' ], array( 'submit', 'reset', 'button' ) ) ) ? $field[ 'type' ] : 'submit'; |
|
| 434 | 434 | |
| 435 | 435 | $attributes = $this->get_field_attributes( $field ); |
| 436 | 436 | $default_value = rgar( $field, 'value' ) ? rgar( $field, 'value' ) : rgar( $field, 'default_value' ); |
| 437 | - $value = $this->get_setting( $field['name'], $default_value ); |
|
| 437 | + $value = $this->get_setting( $field[ 'name' ], $default_value ); |
|
| 438 | 438 | |
| 439 | 439 | |
| 440 | - $attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton'; |
|
| 441 | - $name = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_'.$field['name']; |
|
| 440 | + $attributes[ 'class' ] = isset( $attributes[ 'class' ] ) ? esc_attr( $attributes[ 'class' ] ) : 'button-primary gfbutton'; |
|
| 441 | + $name = ( $field[ 'name' ] === 'gform-settings-save' ) ? $field[ 'name' ] : '_gaddon_setting_' . $field[ 'name' ]; |
|
| 442 | 442 | |
| 443 | 443 | if ( empty( $value ) ) { |
| 444 | 444 | $value = __( 'Update Settings', 'gravityview' ); |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | $attributes = $this->get_field_attributes( $field ); |
| 448 | 448 | |
| 449 | 449 | $html = '<input |
| 450 | - type="' . $field['type'] . '" |
|
| 450 | + type="' . $field[ 'type' ] . '" |
|
| 451 | 451 | name="' . esc_attr( $name ) . '" |
| 452 | 452 | value="' . $value . '" ' . |
| 453 | 453 | implode( ' ', $attributes ) . |
@@ -469,16 +469,16 @@ discard block |
||
| 469 | 469 | * @return string |
| 470 | 470 | */ |
| 471 | 471 | public function settings_save( $field, $echo = true ) { |
| 472 | - $field['type'] = 'submit'; |
|
| 473 | - $field['name'] = 'gform-settings-save'; |
|
| 474 | - $field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton'; |
|
| 472 | + $field[ 'type' ] = 'submit'; |
|
| 473 | + $field[ 'name' ] = 'gform-settings-save'; |
|
| 474 | + $field[ 'class' ] = isset( $field[ 'class' ] ) ? $field[ 'class' ] : 'button-primary gfbutton'; |
|
| 475 | 475 | |
| 476 | 476 | if ( ! rgar( $field, 'value' ) ) |
| 477 | - $field['value'] = __( 'Update Settings', 'gravityview' ); |
|
| 477 | + $field[ 'value' ] = __( 'Update Settings', 'gravityview' ); |
|
| 478 | 478 | |
| 479 | 479 | $output = $this->settings_submit( $field, false ); |
| 480 | 480 | |
| 481 | - if( $echo ) { |
|
| 481 | + if ( $echo ) { |
|
| 482 | 482 | echo $output; |
| 483 | 483 | } |
| 484 | 484 | |
@@ -495,8 +495,8 @@ discard block |
||
| 495 | 495 | parent::single_setting_label( $field ); |
| 496 | 496 | |
| 497 | 497 | // Added by GravityView |
| 498 | - if ( isset( $field['description'] ) ) { |
|
| 499 | - echo '<span class="description">'. $field['description'] .'</span>'; |
|
| 498 | + if ( isset( $field[ 'description' ] ) ) { |
|
| 499 | + echo '<span class="description">' . $field[ 'description' ] . '</span>'; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | } |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | |
| 560 | 560 | // If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response), |
| 561 | 561 | // then we assume it's changed. If it's changed, unset the status and the previous response. |
| 562 | - if( $local_key !== $response_key ) { |
|
| 562 | + if ( $local_key !== $response_key ) { |
|
| 563 | 563 | |
| 564 | - unset( $posted_settings['license_key_response'] ); |
|
| 565 | - unset( $posted_settings['license_key_status'] ); |
|
| 566 | - GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); |
|
| 564 | + unset( $posted_settings[ 'license_key_response' ] ); |
|
| 565 | + unset( $posted_settings[ 'license_key_status' ] ); |
|
| 566 | + GFCommon::add_error_message( __( 'The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | return $posted_settings; |
@@ -598,25 +598,25 @@ discard block |
||
| 598 | 598 | 'label' => __( 'License Key', 'gravityview' ), |
| 599 | 599 | 'description' => __( 'Enter the license key that was sent to you on purchase. This enables plugin updates & support.', 'gravityview' ) . $this->get_license_handler()->license_details( $this->get_app_setting( 'license_key_response' ) ), |
| 600 | 600 | 'type' => 'edd_license', |
| 601 | - 'data-pending-text' => __('Verifying license…', 'gravityview'), |
|
| 602 | - 'default_value' => $default_settings['license_key'], |
|
| 601 | + 'data-pending-text' => __( 'Verifying license…', 'gravityview' ), |
|
| 602 | + 'default_value' => $default_settings[ 'license_key' ], |
|
| 603 | 603 | 'class' => ( '' == $this->get_app_setting( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key', |
| 604 | 604 | ), |
| 605 | 605 | array( |
| 606 | 606 | 'name' => 'license_key_response', |
| 607 | - 'default_value' => $default_settings['license_key_response'], |
|
| 607 | + 'default_value' => $default_settings[ 'license_key_response' ], |
|
| 608 | 608 | 'type' => 'hidden', |
| 609 | 609 | ), |
| 610 | 610 | array( |
| 611 | 611 | 'name' => 'license_key_status', |
| 612 | - 'default_value' => $default_settings['license_key_status'], |
|
| 612 | + 'default_value' => $default_settings[ 'license_key_status' ], |
|
| 613 | 613 | 'type' => 'hidden', |
| 614 | 614 | ), |
| 615 | 615 | array( |
| 616 | 616 | 'name' => 'support-email', |
| 617 | 617 | 'type' => 'text', |
| 618 | 618 | 'validate' => 'email', |
| 619 | - 'default_value' => $default_settings['support-email'], |
|
| 619 | + 'default_value' => $default_settings[ 'support-email' ], |
|
| 620 | 620 | 'label' => __( 'Support Email', 'gravityview' ), |
| 621 | 621 | 'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ), |
| 622 | 622 | 'class' => 'code regular-text', |
@@ -628,44 +628,44 @@ discard block |
||
| 628 | 628 | 'name' => 'support_port', |
| 629 | 629 | 'type' => 'radio', |
| 630 | 630 | 'label' => __( 'Show Support Port?', 'gravityview' ), |
| 631 | - 'default_value' => $default_settings['support_port'], |
|
| 631 | + 'default_value' => $default_settings[ 'support_port' ], |
|
| 632 | 632 | 'horizontal' => 1, |
| 633 | 633 | 'choices' => array( |
| 634 | 634 | array( |
| 635 | - 'label' => _x('Show', 'Setting: Show or Hide', 'gravityview'), |
|
| 635 | + 'label' => _x( 'Show', 'Setting: Show or Hide', 'gravityview' ), |
|
| 636 | 636 | 'value' => '1', |
| 637 | 637 | ), |
| 638 | 638 | array( |
| 639 | - 'label' => _x('Hide', 'Setting: Show or Hide', 'gravityview'), |
|
| 639 | + 'label' => _x( 'Hide', 'Setting: Show or Hide', 'gravityview' ), |
|
| 640 | 640 | 'value' => '0', |
| 641 | 641 | ), |
| 642 | 642 | ), |
| 643 | - '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>', |
|
| 643 | + '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>', |
|
| 644 | 644 | 'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ), |
| 645 | 645 | ), |
| 646 | 646 | array( |
| 647 | 647 | 'name' => 'no-conflict-mode', |
| 648 | 648 | 'type' => 'radio', |
| 649 | 649 | 'label' => __( 'No-Conflict Mode', 'gravityview' ), |
| 650 | - 'default_value' => $default_settings['no-conflict-mode'], |
|
| 650 | + 'default_value' => $default_settings[ 'no-conflict-mode' ], |
|
| 651 | 651 | 'horizontal' => 1, |
| 652 | 652 | 'choices' => array( |
| 653 | 653 | array( |
| 654 | - 'label' => _x('On', 'Setting: On or off', 'gravityview'), |
|
| 654 | + 'label' => _x( 'On', 'Setting: On or off', 'gravityview' ), |
|
| 655 | 655 | 'value' => '1', |
| 656 | 656 | ), |
| 657 | 657 | array( |
| 658 | - 'label' => _x('Off', 'Setting: On or off', 'gravityview'), |
|
| 658 | + 'label' => _x( 'Off', 'Setting: On or off', 'gravityview' ), |
|
| 659 | 659 | 'value' => '0', |
| 660 | 660 | ), |
| 661 | 661 | ), |
| 662 | - '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'), |
|
| 662 | + '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' ), |
|
| 663 | 663 | ), |
| 664 | 664 | array( |
| 665 | 665 | 'name' => 'delete-on-uninstall', |
| 666 | 666 | 'type' => 'radio', |
| 667 | 667 | 'label' => __( 'Remove Data on Delete?', 'gravityview' ), |
| 668 | - 'default_value' => $default_settings['delete-on-uninstall'], |
|
| 668 | + 'default_value' => $default_settings[ 'delete-on-uninstall' ], |
|
| 669 | 669 | 'horizontal' => 1, |
| 670 | 670 | 'choices' => array( |
| 671 | 671 | array( |
@@ -691,20 +691,20 @@ discard block |
||
| 691 | 691 | * @since 1.7.4 |
| 692 | 692 | */ |
| 693 | 693 | foreach ( $fields as &$field ) { |
| 694 | - $field['name'] = isset( $field['name'] ) ? $field['name'] : rgget('id', $field ); |
|
| 695 | - $field['label'] = isset( $field['label'] ) ? $field['label'] : rgget('title', $field ); |
|
| 696 | - $field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : rgget('default', $field ); |
|
| 697 | - $field['description'] = isset( $field['description'] ) ? $field['description'] : rgget('subtitle', $field ); |
|
| 694 | + $field[ 'name' ] = isset( $field[ 'name' ] ) ? $field[ 'name' ] : rgget( 'id', $field ); |
|
| 695 | + $field[ 'label' ] = isset( $field[ 'label' ] ) ? $field[ 'label' ] : rgget( 'title', $field ); |
|
| 696 | + $field[ 'default_value' ] = isset( $field[ 'default_value' ] ) ? $field[ 'default_value' ] : rgget( 'default', $field ); |
|
| 697 | + $field[ 'description' ] = isset( $field[ 'description' ] ) ? $field[ 'description' ] : rgget( 'subtitle', $field ); |
|
| 698 | 698 | |
| 699 | - if( $disabled_attribute ) { |
|
| 700 | - $field['disabled'] = $disabled_attribute; |
|
| 699 | + if ( $disabled_attribute ) { |
|
| 700 | + $field[ 'disabled' ] = $disabled_attribute; |
|
| 701 | 701 | } |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | |
| 705 | 705 | $sections = array( |
| 706 | 706 | array( |
| 707 | - 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
| 707 | + 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __( 'You are running GravityView version %s', 'gravityview' ), GravityView_Plugin::version ) ), |
|
| 708 | 708 | 'fields' => $fields, |
| 709 | 709 | ) |
| 710 | 710 | ); |
@@ -715,8 +715,8 @@ discard block |
||
| 715 | 715 | 'type' => 'save', |
| 716 | 716 | ); |
| 717 | 717 | |
| 718 | - if( $disabled_attribute ) { |
|
| 719 | - $button['disabled'] = $disabled_attribute; |
|
| 718 | + if ( $disabled_attribute ) { |
|
| 719 | + $button[ 'disabled' ] = $disabled_attribute; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -736,20 +736,20 @@ discard block |
||
| 736 | 736 | // If there are extensions, add a section for them |
| 737 | 737 | if ( ! empty( $extension_sections ) ) { |
| 738 | 738 | |
| 739 | - if( $disabled_attribute ) { |
|
| 739 | + if ( $disabled_attribute ) { |
|
| 740 | 740 | foreach ( $extension_sections as &$section ) { |
| 741 | - foreach ( $section['fields'] as &$field ) { |
|
| 742 | - $field['disabled'] = $disabled_attribute; |
|
| 741 | + foreach ( $section[ 'fields' ] as &$field ) { |
|
| 742 | + $field[ 'disabled' ] = $disabled_attribute; |
|
| 743 | 743 | } |
| 744 | 744 | } |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - $k = count( $extension_sections ) - 1 ; |
|
| 748 | - $extension_sections[ $k ]['fields'][] = $button; |
|
| 747 | + $k = count( $extension_sections ) - 1; |
|
| 748 | + $extension_sections[ $k ][ 'fields' ][ ] = $button; |
|
| 749 | 749 | $sections = array_merge( $sections, $extension_sections ); |
| 750 | 750 | } else { |
| 751 | 751 | // add the 'update settings' button to the general section |
| 752 | - $sections[0]['fields'][] = $button; |
|
| 752 | + $sections[ 0 ][ 'fields' ][ ] = $button; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | 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,12 +44,12 @@ 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 | - public $entry; |
|
| 47 | + /** |
|
| 48 | + * Gravity Forms entry array |
|
| 49 | + * |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + public $entry; |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Gravity Forms entry array (it won't get changed during this class lifecycle) |
@@ -58,135 +58,135 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | private static $original_entry = array(); |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Gravity Forms form array (GravityView modifies the content through this class lifecycle) |
|
| 63 | - * |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 61 | + /** |
|
| 62 | + * Gravity Forms form array (GravityView modifies the content through this class lifecycle) |
|
| 63 | + * |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | 66 | public $form; |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Gravity Forms form array (it won't get changed during this class lifecycle) |
|
| 70 | - * @since 1.16.2.1 |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - private static $original_form; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Gravity Forms form array after the form validation process |
|
| 77 | - * @since 1.13 |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 68 | + /** |
|
| 69 | + * Gravity Forms form array (it won't get changed during this class lifecycle) |
|
| 70 | + * @since 1.16.2.1 |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + private static $original_form; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Gravity Forms form array after the form validation process |
|
| 77 | + * @since 1.13 |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | 80 | public $form_after_validation = null; |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Hold an array of GF field objects that have calculation rules |
|
| 84 | - * @var array |
|
| 85 | - */ |
|
| 82 | + /** |
|
| 83 | + * Hold an array of GF field objects that have calculation rules |
|
| 84 | + * @var array |
|
| 85 | + */ |
|
| 86 | 86 | public $fields_with_calculation = array(); |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Hold an array of GF field objects with type 'total' |
|
| 90 | - * @var array |
|
| 91 | - */ |
|
| 88 | + /** |
|
| 89 | + * Hold an array of GF field objects with type 'total' |
|
| 90 | + * @var array |
|
| 91 | + */ |
|
| 92 | 92 | public $total_fields = array(); |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Gravity Forms form id |
|
| 96 | - * |
|
| 97 | - * @var int |
|
| 98 | - */ |
|
| 94 | + /** |
|
| 95 | + * Gravity Forms form id |
|
| 96 | + * |
|
| 97 | + * @var int |
|
| 98 | + */ |
|
| 99 | 99 | public $form_id; |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * ID of the current view |
|
| 103 | - * |
|
| 104 | - * @var int |
|
| 105 | - */ |
|
| 101 | + /** |
|
| 102 | + * ID of the current view |
|
| 103 | + * |
|
| 104 | + * @var int |
|
| 105 | + */ |
|
| 106 | 106 | public $view_id; |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Updated entry is valid (GF Validation object) |
|
| 110 | - * |
|
| 111 | - * @var array |
|
| 112 | - */ |
|
| 108 | + /** |
|
| 109 | + * Updated entry is valid (GF Validation object) |
|
| 110 | + * |
|
| 111 | + * @var array |
|
| 112 | + */ |
|
| 113 | 113 | public $is_valid = NULL; |
| 114 | 114 | |
| 115 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
| 116 | - $this->loader = $loader; |
|
| 117 | - } |
|
| 115 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
| 116 | + $this->loader = $loader; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - function load() { |
|
| 119 | + function load() { |
|
| 120 | 120 | |
| 121 | - /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
| 122 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 121 | + /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
| 122 | + include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 123 | 123 | |
| 124 | - // Don't display an embedded form when editing an entry |
|
| 125 | - add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
|
| 126 | - add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
|
| 124 | + // Don't display an embedded form when editing an entry |
|
| 125 | + add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
|
| 126 | + add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
|
| 127 | 127 | |
| 128 | - // Stop Gravity Forms processing what is ours! |
|
| 129 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 128 | + // Stop Gravity Forms processing what is ours! |
|
| 129 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 130 | 130 | |
| 131 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 131 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 132 | 132 | |
| 133 | - add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
| 133 | + add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
| 134 | 134 | |
| 135 | - // Disable conditional logic if needed (since 1.9) |
|
| 136 | - add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
| 135 | + // Disable conditional logic if needed (since 1.9) |
|
| 136 | + add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
| 137 | 137 | |
| 138 | - // Make sure GF doesn't validate max files (since 1.9) |
|
| 139 | - add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
| 138 | + // Make sure GF doesn't validate max files (since 1.9) |
|
| 139 | + add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
| 140 | 140 | |
| 141 | - // Add fields expected by GFFormDisplay::validate() |
|
| 142 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 141 | + // Add fields expected by GFFormDisplay::validate() |
|
| 142 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 143 | 143 | |
| 144 | - } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Don't show any forms embedded on a page when GravityView is in Edit Entry mode |
|
| 148 | - * |
|
| 149 | - * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action |
|
| 150 | - * And then removes it on the `wp_footer` action |
|
| 151 | - * |
|
| 152 | - * @since 1.16.1 |
|
| 153 | - * |
|
| 154 | - * @return void |
|
| 155 | - */ |
|
| 156 | - public function prevent_render_form() { |
|
| 157 | - if( $this->is_edit_entry() ) { |
|
| 158 | - if( 'wp_head' === current_filter() ) { |
|
| 159 | - add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 160 | - } else { |
|
| 161 | - remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 146 | + /** |
|
| 147 | + * Don't show any forms embedded on a page when GravityView is in Edit Entry mode |
|
| 148 | + * |
|
| 149 | + * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action |
|
| 150 | + * And then removes it on the `wp_footer` action |
|
| 151 | + * |
|
| 152 | + * @since 1.16.1 |
|
| 153 | + * |
|
| 154 | + * @return void |
|
| 155 | + */ |
|
| 156 | + public function prevent_render_form() { |
|
| 157 | + if( $this->is_edit_entry() ) { |
|
| 158 | + if( 'wp_head' === current_filter() ) { |
|
| 159 | + add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 160 | + } else { |
|
| 161 | + remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
| 168 | - * backend form, we need to prevent them from saving twice. |
|
| 169 | - * @return void |
|
| 170 | - */ |
|
| 171 | - public function prevent_maybe_process_form() { |
|
| 166 | + /** |
|
| 167 | + * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
| 168 | + * backend form, we need to prevent them from saving twice. |
|
| 169 | + * @return void |
|
| 170 | + */ |
|
| 171 | + public function prevent_maybe_process_form() { |
|
| 172 | 172 | |
| 173 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 173 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 174 | 174 | |
| 175 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 176 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 177 | - } |
|
| 178 | - } |
|
| 175 | + if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 176 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Is the current page an Edit Entry page? |
|
| 182 | - * @return boolean |
|
| 183 | - */ |
|
| 184 | - public function is_edit_entry() { |
|
| 180 | + /** |
|
| 181 | + * Is the current page an Edit Entry page? |
|
| 182 | + * @return boolean |
|
| 183 | + */ |
|
| 184 | + public function is_edit_entry() { |
|
| 185 | 185 | |
| 186 | - $is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] ); |
|
| 186 | + $is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] ); |
|
| 187 | 187 | |
| 188 | - return ( $is_edit_entry || $this->is_edit_entry_submission() ); |
|
| 189 | - } |
|
| 188 | + return ( $is_edit_entry || $this->is_edit_entry_submission() ); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | 192 | * Is the current page an Edit Entry page? |
@@ -197,653 +197,653 @@ discard block |
||
| 197 | 197 | return !empty( $_POST[ self::$nonce_field ] ); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * When Edit entry view is requested setup the vars |
|
| 202 | - */ |
|
| 203 | - private function setup_vars() { |
|
| 204 | - $gravityview_view = GravityView_View::getInstance(); |
|
| 200 | + /** |
|
| 201 | + * When Edit entry view is requested setup the vars |
|
| 202 | + */ |
|
| 203 | + private function setup_vars() { |
|
| 204 | + $gravityview_view = GravityView_View::getInstance(); |
|
| 205 | 205 | |
| 206 | 206 | |
| 207 | - $entries = $gravityview_view->getEntries(); |
|
| 208 | - self::$original_entry = $entries[0]; |
|
| 209 | - $this->entry = $entries[0]; |
|
| 207 | + $entries = $gravityview_view->getEntries(); |
|
| 208 | + self::$original_entry = $entries[0]; |
|
| 209 | + $this->entry = $entries[0]; |
|
| 210 | 210 | |
| 211 | - self::$original_form = $gravityview_view->getForm(); |
|
| 212 | - $this->form = $gravityview_view->getForm(); |
|
| 213 | - $this->form_id = $gravityview_view->getFormId(); |
|
| 214 | - $this->view_id = $gravityview_view->getViewId(); |
|
| 211 | + self::$original_form = $gravityview_view->getForm(); |
|
| 212 | + $this->form = $gravityview_view->getForm(); |
|
| 213 | + $this->form_id = $gravityview_view->getFormId(); |
|
| 214 | + $this->view_id = $gravityview_view->getViewId(); |
|
| 215 | 215 | |
| 216 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 217 | - } |
|
| 216 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Load required files and trigger edit flow |
|
| 222 | - * |
|
| 223 | - * Run when the is_edit_entry returns true. |
|
| 224 | - * |
|
| 225 | - * @param GravityView_View_Data $gv_data GravityView Data object |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - public function init( $gv_data ) { |
|
| 220 | + /** |
|
| 221 | + * Load required files and trigger edit flow |
|
| 222 | + * |
|
| 223 | + * Run when the is_edit_entry returns true. |
|
| 224 | + * |
|
| 225 | + * @param GravityView_View_Data $gv_data GravityView Data object |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + public function init( $gv_data ) { |
|
| 229 | 229 | |
| 230 | - require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
| 231 | - require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
| 230 | + require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
| 231 | + require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
| 232 | 232 | |
| 233 | - $this->setup_vars(); |
|
| 233 | + $this->setup_vars(); |
|
| 234 | 234 | |
| 235 | - // Multiple Views embedded, don't proceed if nonce fails |
|
| 236 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 237 | - do_action('gravityview_log_error', __METHOD__ . ': Nonce validation failed for the Edit Entry request; returning' ); |
|
| 238 | - return; |
|
| 239 | - } |
|
| 235 | + // Multiple Views embedded, don't proceed if nonce fails |
|
| 236 | + if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 237 | + do_action('gravityview_log_error', __METHOD__ . ': Nonce validation failed for the Edit Entry request; returning' ); |
|
| 238 | + return; |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - // Sorry, you're not allowed here. |
|
| 242 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
| 243 | - do_action('gravityview_log_error', __METHOD__ . ': User is not allowed to edit this entry; returning', $this->entry ); |
|
| 244 | - return; |
|
| 245 | - } |
|
| 241 | + // Sorry, you're not allowed here. |
|
| 242 | + if( false === $this->user_can_edit_entry( true ) ) { |
|
| 243 | + do_action('gravityview_log_error', __METHOD__ . ': User is not allowed to edit this entry; returning', $this->entry ); |
|
| 244 | + return; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - $this->print_scripts(); |
|
| 247 | + $this->print_scripts(); |
|
| 248 | 248 | |
| 249 | - $this->process_save(); |
|
| 249 | + $this->process_save(); |
|
| 250 | 250 | |
| 251 | - $this->edit_entry_form(); |
|
| 251 | + $this->edit_entry_form(); |
|
| 252 | 252 | |
| 253 | - } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Force Gravity Forms to output scripts as if it were in the admin |
|
| 258 | - * @return void |
|
| 259 | - */ |
|
| 260 | - private function print_scripts() { |
|
| 261 | - $gravityview_view = GravityView_View::getInstance(); |
|
| 256 | + /** |
|
| 257 | + * Force Gravity Forms to output scripts as if it were in the admin |
|
| 258 | + * @return void |
|
| 259 | + */ |
|
| 260 | + private function print_scripts() { |
|
| 261 | + $gravityview_view = GravityView_View::getInstance(); |
|
| 262 | 262 | |
| 263 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 263 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 264 | 264 | |
| 265 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 265 | + GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 266 | 266 | |
| 267 | - // Sack is required for images |
|
| 268 | - wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
| 269 | - } |
|
| 267 | + // Sack is required for images |
|
| 268 | + wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Process edit entry form save |
|
| 274 | - */ |
|
| 275 | - private function process_save() { |
|
| 272 | + /** |
|
| 273 | + * Process edit entry form save |
|
| 274 | + */ |
|
| 275 | + private function process_save() { |
|
| 276 | 276 | |
| 277 | - if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) { |
|
| 278 | - return; |
|
| 279 | - } |
|
| 277 | + if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - // Make sure the entry, view, and form IDs are all correct |
|
| 282 | - $valid = $this->verify_nonce(); |
|
| 281 | + // Make sure the entry, view, and form IDs are all correct |
|
| 282 | + $valid = $this->verify_nonce(); |
|
| 283 | 283 | |
| 284 | - if( !$valid ) { |
|
| 285 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 286 | - return; |
|
| 287 | - } |
|
| 284 | + if( !$valid ) { |
|
| 285 | + do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 286 | + return; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 290 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 291 | - return; |
|
| 292 | - } |
|
| 289 | + if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 290 | + do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 291 | + return; |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - do_action('gravityview_log_debug', __METHOD__ . ': $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 294 | + do_action('gravityview_log_debug', __METHOD__ . ': $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 295 | 295 | |
| 296 | - $this->process_save_process_files( $this->form_id ); |
|
| 296 | + $this->process_save_process_files( $this->form_id ); |
|
| 297 | 297 | |
| 298 | - $this->validate(); |
|
| 298 | + $this->validate(); |
|
| 299 | 299 | |
| 300 | - if( $this->is_valid ) { |
|
| 300 | + if( $this->is_valid ) { |
|
| 301 | 301 | |
| 302 | - do_action('gravityview_log_debug', __METHOD__ . ': Submission is valid.' ); |
|
| 302 | + do_action('gravityview_log_debug', __METHOD__ . ': Submission is valid.' ); |
|
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields |
|
| 306 | - */ |
|
| 307 | - $form = $this->form_prepare_for_save(); |
|
| 304 | + /** |
|
| 305 | + * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields |
|
| 306 | + */ |
|
| 307 | + $form = $this->form_prepare_for_save(); |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
| 311 | - */ |
|
| 312 | - unset( $_GET['page'] ); |
|
| 309 | + /** |
|
| 310 | + * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
| 311 | + */ |
|
| 312 | + unset( $_GET['page'] ); |
|
| 313 | 313 | |
| 314 | - $date_created = $this->entry['date_created']; |
|
| 314 | + $date_created = $this->entry['date_created']; |
|
| 315 | 315 | |
| 316 | - /** |
|
| 317 | - * @hack to force Gravity Forms to use $read_value_from_post in GFFormsModel::save_lead() |
|
| 318 | - * @since 1.17.2 |
|
| 319 | - */ |
|
| 320 | - unset( $this->entry['date_created'] ); |
|
| 316 | + /** |
|
| 317 | + * @hack to force Gravity Forms to use $read_value_from_post in GFFormsModel::save_lead() |
|
| 318 | + * @since 1.17.2 |
|
| 319 | + */ |
|
| 320 | + unset( $this->entry['date_created'] ); |
|
| 321 | 321 | |
| 322 | - GFFormsModel::save_lead( $form, $this->entry ); |
|
| 322 | + GFFormsModel::save_lead( $form, $this->entry ); |
|
| 323 | 323 | |
| 324 | - // Delete the values for hidden inputs |
|
| 325 | - $this->unset_hidden_field_values(); |
|
| 324 | + // Delete the values for hidden inputs |
|
| 325 | + $this->unset_hidden_field_values(); |
|
| 326 | 326 | |
| 327 | - $this->entry['date_created'] = $date_created; |
|
| 327 | + $this->entry['date_created'] = $date_created; |
|
| 328 | 328 | |
| 329 | - // If there's a post associated with the entry, process post fields |
|
| 330 | - if( !empty( $this->entry['post_id'] ) ) { |
|
| 331 | - $this->maybe_update_post_fields( $form ); |
|
| 332 | - } |
|
| 329 | + // If there's a post associated with the entry, process post fields |
|
| 330 | + if( !empty( $this->entry['post_id'] ) ) { |
|
| 331 | + $this->maybe_update_post_fields( $form ); |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - // Process calculation fields |
|
| 335 | - $this->update_calculation_fields(); |
|
| 334 | + // Process calculation fields |
|
| 335 | + $this->update_calculation_fields(); |
|
| 336 | 336 | |
| 337 | - // Perform actions normally performed after updating a lead |
|
| 338 | - $this->after_update(); |
|
| 337 | + // Perform actions normally performed after updating a lead |
|
| 338 | + $this->after_update(); |
|
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
| 342 | - * @param array $form Gravity Forms form array |
|
| 343 | - * @param string $entry_id Numeric ID of the entry that was updated |
|
| 344 | - */ |
|
| 345 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 340 | + /** |
|
| 341 | + * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
| 342 | + * @param array $form Gravity Forms form array |
|
| 343 | + * @param string $entry_id Numeric ID of the entry that was updated |
|
| 344 | + */ |
|
| 345 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 346 | 346 | |
| 347 | - } else { |
|
| 348 | - do_action('gravityview_log_error', __METHOD__ . ': Submission is NOT valid.', $this->entry ); |
|
| 349 | - } |
|
| 347 | + } else { |
|
| 348 | + do_action('gravityview_log_error', __METHOD__ . ': Submission is NOT valid.', $this->entry ); |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - } // process_save |
|
| 351 | + } // process_save |
|
| 352 | 352 | |
| 353 | 353 | /** |
| 354 | 354 | * Delete the value of fields hidden by conditional logic when the entry is edited |
| 355 | - * |
|
| 356 | - * @uses GFFormsModel::update_lead_field_value() |
|
| 357 | - * |
|
| 358 | - * @since 1.17.4 |
|
| 359 | - * |
|
| 360 | - * @return void |
|
| 355 | + * |
|
| 356 | + * @uses GFFormsModel::update_lead_field_value() |
|
| 357 | + * |
|
| 358 | + * @since 1.17.4 |
|
| 359 | + * |
|
| 360 | + * @return void |
|
| 361 | + */ |
|
| 362 | + private function unset_hidden_field_values() { |
|
| 363 | + global $wpdb; |
|
| 364 | + |
|
| 365 | + $lead_detail_table = GFFormsModel::get_lead_details_table_name(); |
|
| 366 | + $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) ); |
|
| 367 | + |
|
| 368 | + foreach ( $this->entry as $input_id => $field_value ) { |
|
| 369 | + |
|
| 370 | + $field = RGFormsModel::get_field( $this->form, $input_id ); |
|
| 371 | + |
|
| 372 | + // Reset fields that are hidden |
|
| 373 | + // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic |
|
| 374 | + if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) { |
|
| 375 | + |
|
| 376 | + // List fields are stored as empty arrays when empty |
|
| 377 | + $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : ''; |
|
| 378 | + |
|
| 379 | + $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id ); |
|
| 380 | + |
|
| 381 | + GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value ); |
|
| 382 | + |
|
| 383 | + // Prevent the $_POST values of hidden fields from being used as default values when rendering the form |
|
| 384 | + // after submission |
|
| 385 | + $post_input_id = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 386 | + $_POST[ $post_input_id ] = ''; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Have GF handle file uploads |
|
| 393 | + * |
|
| 394 | + * Copy of code from GFFormDisplay::process_form() |
|
| 395 | + * |
|
| 396 | + * @param int $form_id |
|
| 397 | + */ |
|
| 398 | + private function process_save_process_files( $form_id ) { |
|
| 399 | + |
|
| 400 | + //Loading files that have been uploaded to temp folder |
|
| 401 | + $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
| 402 | + if ( ! is_array( $files ) ) { |
|
| 403 | + $files = array(); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
| 411 | + * Late validation done on self::custom_validation |
|
| 412 | + * |
|
| 413 | + * @param $plupload_init array Plupload settings |
|
| 414 | + * @param $form_id |
|
| 415 | + * @param $instance |
|
| 416 | + * @return mixed |
|
| 417 | + */ |
|
| 418 | + public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
| 419 | + if( ! $this->is_edit_entry() ) { |
|
| 420 | + return $plupload_init; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + $plupload_init['gf_vars']['max_files'] = 0; |
|
| 424 | + |
|
| 425 | + return $plupload_init; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Unset adminOnly and convert field input key to string |
|
| 431 | + * @return array $form |
|
| 432 | + */ |
|
| 433 | + private function form_prepare_for_save() { |
|
| 434 | + |
|
| 435 | + $form = $this->form; |
|
| 436 | + |
|
| 437 | + /** @var GF_Field $field */ |
|
| 438 | + foreach( $form['fields'] as $k => &$field ) { |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Remove the fields with calculation formulas before save to avoid conflicts with GF logic |
|
| 442 | + * @since 1.16.3 |
|
| 443 | + * @var GF_Field $field |
|
| 444 | + */ |
|
| 445 | + if( $field->has_calculation() ) { |
|
| 446 | + unset( $form['fields'][ $k ] ); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + $field->adminOnly = false; |
|
| 450 | + |
|
| 451 | + if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 452 | + foreach( $field->inputs as $key => $input ) { |
|
| 453 | + $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return $form; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + private function update_calculation_fields() { |
|
| 462 | + |
|
| 463 | + $form = self::$original_form; |
|
| 464 | + $update = false; |
|
| 465 | + |
|
| 466 | + // get the most up to date entry values |
|
| 467 | + $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 468 | + |
|
| 469 | + if( !empty( $this->fields_with_calculation ) ) { |
|
| 470 | + $update = true; |
|
| 471 | + foreach ( $this->fields_with_calculation as $calc_field ) { |
|
| 472 | + $inputs = $calc_field->get_entry_inputs(); |
|
| 473 | + if ( is_array( $inputs ) ) { |
|
| 474 | + foreach ( $inputs as $input ) { |
|
| 475 | + $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 476 | + $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 477 | + } |
|
| 478 | + } else { |
|
| 479 | + $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 480 | + $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + //saving total field as the last field of the form. |
|
| 487 | + if ( ! empty( $this->total_fields ) ) { |
|
| 488 | + $update = true; |
|
| 489 | + foreach ( $this->total_fields as $total_field ) { |
|
| 490 | + $input_name = 'input_' . str_replace( '.', '_', $total_field->id); |
|
| 491 | + $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry ); |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if( $update ) { |
|
| 496 | + |
|
| 497 | + $return_entry = GFAPI::update_entry( $entry ); |
|
| 498 | + |
|
| 499 | + if( is_wp_error( $return_entry ) ) { |
|
| 500 | + do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry ); |
|
| 501 | + } else { |
|
| 502 | + do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' ); |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Handle updating the Post Image field |
|
| 509 | + * |
|
| 510 | + * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media |
|
| 511 | + * |
|
| 512 | + * @since 1.17 |
|
| 513 | + * |
|
| 514 | + * @uses GFFormsModel::media_handle_upload |
|
| 515 | + * @uses set_post_thumbnail |
|
| 516 | + * |
|
| 517 | + * @param array $form GF Form array |
|
| 518 | + * @param GF_Field $field GF Field |
|
| 519 | + * @param string $field_id Numeric ID of the field |
|
| 520 | + * @param string $value |
|
| 521 | + * @param array $entry GF Entry currently being edited |
|
| 522 | + * @param int $post_id ID of the Post being edited |
|
| 523 | + * |
|
| 524 | + * @return mixed|string |
|
| 525 | + */ |
|
| 526 | + private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) { |
|
| 527 | + |
|
| 528 | + $input_name = 'input_' . $field_id; |
|
| 529 | + |
|
| 530 | + if ( !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 531 | + |
|
| 532 | + // We have a new image |
|
| 533 | + |
|
| 534 | + $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
|
| 535 | + |
|
| 536 | + $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
|
| 537 | + $img_url = rgar( $ary, 0 ); |
|
| 538 | + |
|
| 539 | + $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
|
| 540 | + $img_caption = count( $ary ) > 2 ? $ary[2] : ''; |
|
| 541 | + $img_description = count( $ary ) > 3 ? $ary[3] : ''; |
|
| 542 | + |
|
| 543 | + $image_meta = array( |
|
| 544 | + 'post_excerpt' => $img_caption, |
|
| 545 | + 'post_content' => $img_description, |
|
| 546 | + ); |
|
| 547 | + |
|
| 548 | + //adding title only if it is not empty. It will default to the file name if it is not in the array |
|
| 549 | + if ( ! empty( $img_title ) ) { |
|
| 550 | + $image_meta['post_title'] = $img_title; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * 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. |
|
| 555 | + * Note: the method became public in GF 1.9.17.7, but we don't require that version yet. |
|
| 556 | + */ |
|
| 557 | + require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 558 | + $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta ); |
|
| 559 | + |
|
| 560 | + // is this field set as featured image? |
|
| 561 | + if ( $media_id && $field->postFeaturedImage ) { |
|
| 562 | + set_post_thumbnail( $post_id, $media_id ); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 566 | + |
|
| 567 | + // Same image although the image title, caption or description might have changed |
|
| 568 | + |
|
| 569 | + $ary = array(); |
|
| 570 | + if( ! empty( $entry[ $field_id ] ) ) { |
|
| 571 | + $ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] ); |
|
| 572 | + } |
|
| 573 | + $img_url = rgar( $ary, 0 ); |
|
| 574 | + |
|
| 575 | + // is this really the same image or something went wrong ? |
|
| 576 | + if( $img_url === $_POST[ $input_name ] ) { |
|
| 577 | + |
|
| 578 | + $img_title = rgar( $value, $field_id .'.1' ); |
|
| 579 | + $img_caption = rgar( $value, $field_id .'.4' ); |
|
| 580 | + $img_description = rgar( $value, $field_id .'.7' ); |
|
| 581 | + |
|
| 582 | + $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; |
|
| 583 | + |
|
| 584 | + if ( $field->postFeaturedImage ) { |
|
| 585 | + |
|
| 586 | + $image_meta = array( |
|
| 587 | + 'ID' => get_post_thumbnail_id( $post_id ), |
|
| 588 | + 'post_title' => $img_title, |
|
| 589 | + 'post_excerpt' => $img_caption, |
|
| 590 | + 'post_content' => $img_description, |
|
| 591 | + ); |
|
| 592 | + |
|
| 593 | + // update image title, caption or description |
|
| 594 | + wp_update_post( $image_meta ); |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + } else { |
|
| 599 | + |
|
| 600 | + // if we get here, image was removed or not set. |
|
| 601 | + $value = ''; |
|
| 602 | + |
|
| 603 | + if ( $field->postFeaturedImage ) { |
|
| 604 | + delete_post_thumbnail( $post_id ); |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + return $value; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
| 613 | + * |
|
| 614 | + * @param array $form Gravity Forms form |
|
| 615 | + * |
|
| 616 | + * @return void |
|
| 361 | 617 | */ |
| 362 | - private function unset_hidden_field_values() { |
|
| 363 | - global $wpdb; |
|
| 364 | - |
|
| 365 | - $lead_detail_table = GFFormsModel::get_lead_details_table_name(); |
|
| 366 | - $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) ); |
|
| 367 | - |
|
| 368 | - foreach ( $this->entry as $input_id => $field_value ) { |
|
| 369 | - |
|
| 370 | - $field = RGFormsModel::get_field( $this->form, $input_id ); |
|
| 371 | - |
|
| 372 | - // Reset fields that are hidden |
|
| 373 | - // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic |
|
| 374 | - if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) { |
|
| 375 | - |
|
| 376 | - // List fields are stored as empty arrays when empty |
|
| 377 | - $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : ''; |
|
| 378 | - |
|
| 379 | - $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id ); |
|
| 380 | - |
|
| 381 | - GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value ); |
|
| 382 | - |
|
| 383 | - // Prevent the $_POST values of hidden fields from being used as default values when rendering the form |
|
| 384 | - // after submission |
|
| 385 | - $post_input_id = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 386 | - $_POST[ $post_input_id ] = ''; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Have GF handle file uploads |
|
| 393 | - * |
|
| 394 | - * Copy of code from GFFormDisplay::process_form() |
|
| 395 | - * |
|
| 396 | - * @param int $form_id |
|
| 397 | - */ |
|
| 398 | - private function process_save_process_files( $form_id ) { |
|
| 399 | - |
|
| 400 | - //Loading files that have been uploaded to temp folder |
|
| 401 | - $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
| 402 | - if ( ! is_array( $files ) ) { |
|
| 403 | - $files = array(); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
| 411 | - * Late validation done on self::custom_validation |
|
| 412 | - * |
|
| 413 | - * @param $plupload_init array Plupload settings |
|
| 414 | - * @param $form_id |
|
| 415 | - * @param $instance |
|
| 416 | - * @return mixed |
|
| 417 | - */ |
|
| 418 | - public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
| 419 | - if( ! $this->is_edit_entry() ) { |
|
| 420 | - return $plupload_init; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - $plupload_init['gf_vars']['max_files'] = 0; |
|
| 424 | - |
|
| 425 | - return $plupload_init; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Unset adminOnly and convert field input key to string |
|
| 431 | - * @return array $form |
|
| 432 | - */ |
|
| 433 | - private function form_prepare_for_save() { |
|
| 434 | - |
|
| 435 | - $form = $this->form; |
|
| 436 | - |
|
| 437 | - /** @var GF_Field $field */ |
|
| 438 | - foreach( $form['fields'] as $k => &$field ) { |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Remove the fields with calculation formulas before save to avoid conflicts with GF logic |
|
| 442 | - * @since 1.16.3 |
|
| 443 | - * @var GF_Field $field |
|
| 444 | - */ |
|
| 445 | - if( $field->has_calculation() ) { |
|
| 446 | - unset( $form['fields'][ $k ] ); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $field->adminOnly = false; |
|
| 450 | - |
|
| 451 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 452 | - foreach( $field->inputs as $key => $input ) { |
|
| 453 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - return $form; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - private function update_calculation_fields() { |
|
| 462 | - |
|
| 463 | - $form = self::$original_form; |
|
| 464 | - $update = false; |
|
| 465 | - |
|
| 466 | - // get the most up to date entry values |
|
| 467 | - $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 468 | - |
|
| 469 | - if( !empty( $this->fields_with_calculation ) ) { |
|
| 470 | - $update = true; |
|
| 471 | - foreach ( $this->fields_with_calculation as $calc_field ) { |
|
| 472 | - $inputs = $calc_field->get_entry_inputs(); |
|
| 473 | - if ( is_array( $inputs ) ) { |
|
| 474 | - foreach ( $inputs as $input ) { |
|
| 475 | - $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 476 | - $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 477 | - } |
|
| 478 | - } else { |
|
| 479 | - $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 480 | - $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - //saving total field as the last field of the form. |
|
| 487 | - if ( ! empty( $this->total_fields ) ) { |
|
| 488 | - $update = true; |
|
| 489 | - foreach ( $this->total_fields as $total_field ) { |
|
| 490 | - $input_name = 'input_' . str_replace( '.', '_', $total_field->id); |
|
| 491 | - $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry ); |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if( $update ) { |
|
| 496 | - |
|
| 497 | - $return_entry = GFAPI::update_entry( $entry ); |
|
| 498 | - |
|
| 499 | - if( is_wp_error( $return_entry ) ) { |
|
| 500 | - do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry ); |
|
| 501 | - } else { |
|
| 502 | - do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' ); |
|
| 503 | - } |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Handle updating the Post Image field |
|
| 509 | - * |
|
| 510 | - * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media |
|
| 511 | - * |
|
| 512 | - * @since 1.17 |
|
| 513 | - * |
|
| 514 | - * @uses GFFormsModel::media_handle_upload |
|
| 515 | - * @uses set_post_thumbnail |
|
| 516 | - * |
|
| 517 | - * @param array $form GF Form array |
|
| 518 | - * @param GF_Field $field GF Field |
|
| 519 | - * @param string $field_id Numeric ID of the field |
|
| 520 | - * @param string $value |
|
| 521 | - * @param array $entry GF Entry currently being edited |
|
| 522 | - * @param int $post_id ID of the Post being edited |
|
| 523 | - * |
|
| 524 | - * @return mixed|string |
|
| 525 | - */ |
|
| 526 | - private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) { |
|
| 527 | - |
|
| 528 | - $input_name = 'input_' . $field_id; |
|
| 529 | - |
|
| 530 | - if ( !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 531 | - |
|
| 532 | - // We have a new image |
|
| 533 | - |
|
| 534 | - $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
|
| 535 | - |
|
| 536 | - $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
|
| 537 | - $img_url = rgar( $ary, 0 ); |
|
| 538 | - |
|
| 539 | - $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
|
| 540 | - $img_caption = count( $ary ) > 2 ? $ary[2] : ''; |
|
| 541 | - $img_description = count( $ary ) > 3 ? $ary[3] : ''; |
|
| 542 | - |
|
| 543 | - $image_meta = array( |
|
| 544 | - 'post_excerpt' => $img_caption, |
|
| 545 | - 'post_content' => $img_description, |
|
| 546 | - ); |
|
| 547 | - |
|
| 548 | - //adding title only if it is not empty. It will default to the file name if it is not in the array |
|
| 549 | - if ( ! empty( $img_title ) ) { |
|
| 550 | - $image_meta['post_title'] = $img_title; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * 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. |
|
| 555 | - * Note: the method became public in GF 1.9.17.7, but we don't require that version yet. |
|
| 556 | - */ |
|
| 557 | - require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 558 | - $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta ); |
|
| 559 | - |
|
| 560 | - // is this field set as featured image? |
|
| 561 | - if ( $media_id && $field->postFeaturedImage ) { |
|
| 562 | - set_post_thumbnail( $post_id, $media_id ); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 566 | - |
|
| 567 | - // Same image although the image title, caption or description might have changed |
|
| 568 | - |
|
| 569 | - $ary = array(); |
|
| 570 | - if( ! empty( $entry[ $field_id ] ) ) { |
|
| 571 | - $ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] ); |
|
| 572 | - } |
|
| 573 | - $img_url = rgar( $ary, 0 ); |
|
| 574 | - |
|
| 575 | - // is this really the same image or something went wrong ? |
|
| 576 | - if( $img_url === $_POST[ $input_name ] ) { |
|
| 577 | - |
|
| 578 | - $img_title = rgar( $value, $field_id .'.1' ); |
|
| 579 | - $img_caption = rgar( $value, $field_id .'.4' ); |
|
| 580 | - $img_description = rgar( $value, $field_id .'.7' ); |
|
| 581 | - |
|
| 582 | - $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; |
|
| 583 | - |
|
| 584 | - if ( $field->postFeaturedImage ) { |
|
| 585 | - |
|
| 586 | - $image_meta = array( |
|
| 587 | - 'ID' => get_post_thumbnail_id( $post_id ), |
|
| 588 | - 'post_title' => $img_title, |
|
| 589 | - 'post_excerpt' => $img_caption, |
|
| 590 | - 'post_content' => $img_description, |
|
| 591 | - ); |
|
| 592 | - |
|
| 593 | - // update image title, caption or description |
|
| 594 | - wp_update_post( $image_meta ); |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - } else { |
|
| 599 | - |
|
| 600 | - // if we get here, image was removed or not set. |
|
| 601 | - $value = ''; |
|
| 602 | - |
|
| 603 | - if ( $field->postFeaturedImage ) { |
|
| 604 | - delete_post_thumbnail( $post_id ); |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - return $value; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
| 613 | - * |
|
| 614 | - * @param array $form Gravity Forms form |
|
| 615 | - * |
|
| 616 | - * @return void |
|
| 617 | - */ |
|
| 618 | - private function maybe_update_post_fields( $form ) { |
|
| 618 | + private function maybe_update_post_fields( $form ) { |
|
| 619 | 619 | |
| 620 | - $post_id = $this->entry['post_id']; |
|
| 620 | + $post_id = $this->entry['post_id']; |
|
| 621 | 621 | |
| 622 | - // Security check |
|
| 623 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 624 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 625 | - return; |
|
| 626 | - } |
|
| 622 | + // Security check |
|
| 623 | + if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 624 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 625 | + return; |
|
| 626 | + } |
|
| 627 | 627 | |
| 628 | - $update_entry = false; |
|
| 628 | + $update_entry = false; |
|
| 629 | 629 | |
| 630 | - $updated_post = $original_post = get_post( $post_id ); |
|
| 630 | + $updated_post = $original_post = get_post( $post_id ); |
|
| 631 | 631 | |
| 632 | - foreach ( $this->entry as $field_id => $value ) { |
|
| 632 | + foreach ( $this->entry as $field_id => $value ) { |
|
| 633 | 633 | |
| 634 | - $field = RGFormsModel::get_field( $form, $field_id ); |
|
| 634 | + $field = RGFormsModel::get_field( $form, $field_id ); |
|
| 635 | 635 | |
| 636 | - if( ! $field ) { |
|
| 637 | - continue; |
|
| 638 | - } |
|
| 636 | + if( ! $field ) { |
|
| 637 | + continue; |
|
| 638 | + } |
|
| 639 | 639 | |
| 640 | - if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) { |
|
| 640 | + if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) { |
|
| 641 | 641 | |
| 642 | - // Get the value of the field, including $_POSTed value |
|
| 643 | - $value = RGFormsModel::get_field_value( $field ); |
|
| 642 | + // Get the value of the field, including $_POSTed value |
|
| 643 | + $value = RGFormsModel::get_field_value( $field ); |
|
| 644 | 644 | |
| 645 | - // Use temporary entry variable, to make values available to fill_post_template() and update_post_image() |
|
| 646 | - $entry_tmp = $this->entry; |
|
| 647 | - $entry_tmp["{$field_id}"] = $value; |
|
| 645 | + // Use temporary entry variable, to make values available to fill_post_template() and update_post_image() |
|
| 646 | + $entry_tmp = $this->entry; |
|
| 647 | + $entry_tmp["{$field_id}"] = $value; |
|
| 648 | 648 | |
| 649 | - switch( $field->type ) { |
|
| 649 | + switch( $field->type ) { |
|
| 650 | 650 | |
| 651 | - case 'post_title': |
|
| 652 | - $post_title = $value; |
|
| 653 | - if( rgar( $form, 'postTitleTemplateEnabled' ) ) { |
|
| 654 | - $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp ); |
|
| 655 | - } |
|
| 656 | - $updated_post->post_title = $post_title; |
|
| 657 | - $updated_post->post_name = $post_title; |
|
| 658 | - unset( $post_title ); |
|
| 659 | - break; |
|
| 651 | + case 'post_title': |
|
| 652 | + $post_title = $value; |
|
| 653 | + if( rgar( $form, 'postTitleTemplateEnabled' ) ) { |
|
| 654 | + $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp ); |
|
| 655 | + } |
|
| 656 | + $updated_post->post_title = $post_title; |
|
| 657 | + $updated_post->post_name = $post_title; |
|
| 658 | + unset( $post_title ); |
|
| 659 | + break; |
|
| 660 | 660 | |
| 661 | - case 'post_content': |
|
| 662 | - $post_content = $value; |
|
| 663 | - if( rgar( $form, 'postContentTemplateEnabled' ) ) { |
|
| 664 | - $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true ); |
|
| 665 | - } |
|
| 666 | - $updated_post->post_content = $post_content; |
|
| 667 | - unset( $post_content ); |
|
| 668 | - break; |
|
| 669 | - case 'post_excerpt': |
|
| 670 | - $updated_post->post_excerpt = $value; |
|
| 671 | - break; |
|
| 672 | - case 'post_tags': |
|
| 673 | - wp_set_post_tags( $post_id, $value, false ); |
|
| 674 | - break; |
|
| 675 | - case 'post_category': |
|
| 676 | - break; |
|
| 677 | - case 'post_custom_field': |
|
| 678 | - if( ! empty( $field->customFieldTemplateEnabled ) ) { |
|
| 679 | - $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true ); |
|
| 680 | - } |
|
| 661 | + case 'post_content': |
|
| 662 | + $post_content = $value; |
|
| 663 | + if( rgar( $form, 'postContentTemplateEnabled' ) ) { |
|
| 664 | + $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true ); |
|
| 665 | + } |
|
| 666 | + $updated_post->post_content = $post_content; |
|
| 667 | + unset( $post_content ); |
|
| 668 | + break; |
|
| 669 | + case 'post_excerpt': |
|
| 670 | + $updated_post->post_excerpt = $value; |
|
| 671 | + break; |
|
| 672 | + case 'post_tags': |
|
| 673 | + wp_set_post_tags( $post_id, $value, false ); |
|
| 674 | + break; |
|
| 675 | + case 'post_category': |
|
| 676 | + break; |
|
| 677 | + case 'post_custom_field': |
|
| 678 | + if( ! empty( $field->customFieldTemplateEnabled ) ) { |
|
| 679 | + $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true ); |
|
| 680 | + } |
|
| 681 | 681 | |
| 682 | - if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) { |
|
| 683 | - $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 684 | - } |
|
| 682 | + if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) { |
|
| 683 | + $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 684 | + } |
|
| 685 | 685 | |
| 686 | - update_post_meta( $post_id, $field->postCustomFieldName, $value ); |
|
| 686 | + update_post_meta( $post_id, $field->postCustomFieldName, $value ); |
|
| 687 | 687 | |
| 688 | - break; |
|
| 688 | + break; |
|
| 689 | 689 | |
| 690 | - case 'post_image': |
|
| 691 | - $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id ); |
|
| 692 | - break; |
|
| 690 | + case 'post_image': |
|
| 691 | + $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id ); |
|
| 692 | + break; |
|
| 693 | 693 | |
| 694 | - } |
|
| 694 | + } |
|
| 695 | 695 | |
| 696 | - // update entry after |
|
| 697 | - $this->entry["{$field_id}"] = $value; |
|
| 696 | + // update entry after |
|
| 697 | + $this->entry["{$field_id}"] = $value; |
|
| 698 | 698 | |
| 699 | - $update_entry = true; |
|
| 699 | + $update_entry = true; |
|
| 700 | 700 | |
| 701 | - unset( $entry_tmp ); |
|
| 702 | - } |
|
| 701 | + unset( $entry_tmp ); |
|
| 702 | + } |
|
| 703 | 703 | |
| 704 | - } |
|
| 704 | + } |
|
| 705 | 705 | |
| 706 | - if( $update_entry ) { |
|
| 706 | + if( $update_entry ) { |
|
| 707 | 707 | |
| 708 | - $return_entry = GFAPI::update_entry( $this->entry ); |
|
| 708 | + $return_entry = GFAPI::update_entry( $this->entry ); |
|
| 709 | 709 | |
| 710 | - if( is_wp_error( $return_entry ) ) { |
|
| 711 | - do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) ); |
|
| 712 | - } else { |
|
| 713 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 714 | - } |
|
| 710 | + if( is_wp_error( $return_entry ) ) { |
|
| 711 | + do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) ); |
|
| 712 | + } else { |
|
| 713 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | - } |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - $return_post = wp_update_post( $updated_post, true ); |
|
| 718 | + $return_post = wp_update_post( $updated_post, true ); |
|
| 719 | 719 | |
| 720 | - if( is_wp_error( $return_post ) ) { |
|
| 721 | - $return_post->add_data( $updated_post, '$updated_post' ); |
|
| 722 | - do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) ); |
|
| 723 | - } else { |
|
| 724 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); |
|
| 725 | - } |
|
| 726 | - } |
|
| 720 | + if( is_wp_error( $return_post ) ) { |
|
| 721 | + $return_post->add_data( $updated_post, '$updated_post' ); |
|
| 722 | + do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) ); |
|
| 723 | + } else { |
|
| 724 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | 727 | |
| 728 | 728 | /** |
| 729 | - * Is the field stored in a JSON-encoded manner? |
|
| 730 | - * |
|
| 729 | + * Is the field stored in a JSON-encoded manner? |
|
| 730 | + * |
|
| 731 | 731 | * @param GF_Field $field |
| 732 | 732 | * |
| 733 | 733 | * @return bool True: stored in DB json_encode()'d; False: not encoded |
| 734 | 734 | */ |
| 735 | - private function is_field_json_encoded( $field ) { |
|
| 735 | + private function is_field_json_encoded( $field ) { |
|
| 736 | 736 | |
| 737 | - $json_encoded = false; |
|
| 737 | + $json_encoded = false; |
|
| 738 | 738 | |
| 739 | - $input_type = RGFormsModel::get_input_type( $field ); |
|
| 739 | + $input_type = RGFormsModel::get_input_type( $field ); |
|
| 740 | 740 | |
| 741 | - // Only certain custom field types are supported |
|
| 742 | - switch( $input_type ) { |
|
| 743 | - case 'fileupload': |
|
| 744 | - case 'list': |
|
| 745 | - case 'multiselect': |
|
| 746 | - $json_encoded = true; |
|
| 747 | - break; |
|
| 748 | - } |
|
| 741 | + // Only certain custom field types are supported |
|
| 742 | + switch( $input_type ) { |
|
| 743 | + case 'fileupload': |
|
| 744 | + case 'list': |
|
| 745 | + case 'multiselect': |
|
| 746 | + $json_encoded = true; |
|
| 747 | + break; |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - return $json_encoded; |
|
| 751 | - } |
|
| 750 | + return $json_encoded; |
|
| 751 | + } |
|
| 752 | 752 | |
| 753 | - /** |
|
| 754 | - * Convert a field content template into prepared output |
|
| 755 | - * |
|
| 756 | - * @uses GravityView_GFFormsModel::get_post_field_images() |
|
| 757 | - * |
|
| 758 | - * @since 1.17 |
|
| 759 | - * |
|
| 760 | - * @param string $template The content template for the field |
|
| 761 | - * @param array $form Gravity Forms form |
|
| 762 | - * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields |
|
| 763 | - * |
|
| 764 | - * @return mixed|string|void |
|
| 765 | - */ |
|
| 766 | - private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) { |
|
| 753 | + /** |
|
| 754 | + * Convert a field content template into prepared output |
|
| 755 | + * |
|
| 756 | + * @uses GravityView_GFFormsModel::get_post_field_images() |
|
| 757 | + * |
|
| 758 | + * @since 1.17 |
|
| 759 | + * |
|
| 760 | + * @param string $template The content template for the field |
|
| 761 | + * @param array $form Gravity Forms form |
|
| 762 | + * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields |
|
| 763 | + * |
|
| 764 | + * @return mixed|string|void |
|
| 765 | + */ |
|
| 766 | + private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) { |
|
| 767 | 767 | |
| 768 | - require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 768 | + require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 769 | 769 | |
| 770 | - $post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry ); |
|
| 770 | + $post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry ); |
|
| 771 | 771 | |
| 772 | - //replacing post image variables |
|
| 773 | - $output = GFCommon::replace_variables_post_image( $template, $post_images, $entry ); |
|
| 772 | + //replacing post image variables |
|
| 773 | + $output = GFCommon::replace_variables_post_image( $template, $post_images, $entry ); |
|
| 774 | 774 | |
| 775 | - //replacing all other variables |
|
| 776 | - $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false ); |
|
| 775 | + //replacing all other variables |
|
| 776 | + $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false ); |
|
| 777 | 777 | |
| 778 | - // replace conditional shortcodes |
|
| 779 | - if( $do_shortcode ) { |
|
| 780 | - $output = do_shortcode( $output ); |
|
| 781 | - } |
|
| 778 | + // replace conditional shortcodes |
|
| 779 | + if( $do_shortcode ) { |
|
| 780 | + $output = do_shortcode( $output ); |
|
| 781 | + } |
|
| 782 | 782 | |
| 783 | - return $output; |
|
| 784 | - } |
|
| 783 | + return $output; |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | 786 | |
| 787 | - /** |
|
| 788 | - * Perform actions normally performed after updating a lead |
|
| 789 | - * |
|
| 790 | - * @since 1.8 |
|
| 791 | - * |
|
| 792 | - * @see GFEntryDetail::lead_detail_page() |
|
| 793 | - * |
|
| 794 | - * @return void |
|
| 795 | - */ |
|
| 796 | - private function after_update() { |
|
| 787 | + /** |
|
| 788 | + * Perform actions normally performed after updating a lead |
|
| 789 | + * |
|
| 790 | + * @since 1.8 |
|
| 791 | + * |
|
| 792 | + * @see GFEntryDetail::lead_detail_page() |
|
| 793 | + * |
|
| 794 | + * @return void |
|
| 795 | + */ |
|
| 796 | + private function after_update() { |
|
| 797 | 797 | |
| 798 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry ); |
|
| 799 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 798 | + do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry ); |
|
| 799 | + do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 800 | 800 | |
| 801 | - // Re-define the entry now that we've updated it. |
|
| 802 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 801 | + // Re-define the entry now that we've updated it. |
|
| 802 | + $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 803 | 803 | |
| 804 | - $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
| 804 | + $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
| 805 | 805 | |
| 806 | - // We need to clear the cache because Gravity Forms caches the field values, which |
|
| 807 | - // we have just updated. |
|
| 808 | - foreach ($this->form['fields'] as $key => $field) { |
|
| 809 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 810 | - } |
|
| 806 | + // We need to clear the cache because Gravity Forms caches the field values, which |
|
| 807 | + // we have just updated. |
|
| 808 | + foreach ($this->form['fields'] as $key => $field) { |
|
| 809 | + GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 810 | + } |
|
| 811 | 811 | |
| 812 | - $this->entry = $entry; |
|
| 813 | - } |
|
| 812 | + $this->entry = $entry; |
|
| 813 | + } |
|
| 814 | 814 | |
| 815 | 815 | |
| 816 | - /** |
|
| 817 | - * Display the Edit Entry form |
|
| 818 | - * |
|
| 819 | - * @return void |
|
| 820 | - */ |
|
| 821 | - public function edit_entry_form() { |
|
| 816 | + /** |
|
| 817 | + * Display the Edit Entry form |
|
| 818 | + * |
|
| 819 | + * @return void |
|
| 820 | + */ |
|
| 821 | + public function edit_entry_form() { |
|
| 822 | 822 | |
| 823 | - ?> |
|
| 823 | + ?> |
|
| 824 | 824 | |
| 825 | 825 | <div class="gv-edit-entry-wrapper"><?php |
| 826 | 826 | |
| 827 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 827 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 828 | 828 | |
| 829 | - /** |
|
| 830 | - * Fixes weird wpautop() issue |
|
| 831 | - * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
| 832 | - */ |
|
| 833 | - echo gravityview_strip_whitespace( $javascript ); |
|
| 829 | + /** |
|
| 830 | + * Fixes weird wpautop() issue |
|
| 831 | + * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
| 832 | + */ |
|
| 833 | + echo gravityview_strip_whitespace( $javascript ); |
|
| 834 | 834 | |
| 835 | - ?><h2 class="gv-edit-entry-title"> |
|
| 835 | + ?><h2 class="gv-edit-entry-title"> |
|
| 836 | 836 | <span><?php |
| 837 | 837 | |
| 838 | - /** |
|
| 839 | - * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 840 | - * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 841 | - * @param GravityView_Edit_Entry_Render $this This object |
|
| 842 | - */ |
|
| 843 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 838 | + /** |
|
| 839 | + * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 840 | + * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 841 | + * @param GravityView_Edit_Entry_Render $this This object |
|
| 842 | + */ |
|
| 843 | + $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 844 | 844 | |
| 845 | - echo esc_attr( $edit_entry_title ); |
|
| 846 | - ?></span> |
|
| 845 | + echo esc_attr( $edit_entry_title ); |
|
| 846 | + ?></span> |
|
| 847 | 847 | </h2> |
| 848 | 848 | |
| 849 | 849 | <?php $this->maybe_print_message(); ?> |
@@ -854,14 +854,14 @@ discard block |
||
| 854 | 854 | |
| 855 | 855 | <?php |
| 856 | 856 | |
| 857 | - wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
| 857 | + wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
| 858 | 858 | |
| 859 | - wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
| 859 | + wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
| 860 | 860 | |
| 861 | - // Print the actual form HTML |
|
| 862 | - $this->render_edit_form(); |
|
| 861 | + // Print the actual form HTML |
|
| 862 | + $this->render_edit_form(); |
|
| 863 | 863 | |
| 864 | - ?> |
|
| 864 | + ?> |
|
| 865 | 865 | </form> |
| 866 | 866 | |
| 867 | 867 | <script> |
@@ -873,1154 +873,1154 @@ discard block |
||
| 873 | 873 | </div> |
| 874 | 874 | |
| 875 | 875 | <?php |
| 876 | - } |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * Display success or error message if the form has been submitted |
|
| 880 | - * |
|
| 881 | - * @uses GVCommon::generate_notice |
|
| 882 | - * |
|
| 883 | - * @since 1.16.2.2 |
|
| 884 | - * |
|
| 885 | - * @return void |
|
| 886 | - */ |
|
| 887 | - private function maybe_print_message() { |
|
| 888 | - |
|
| 889 | - if( rgpost('action') === 'update' ) { |
|
| 890 | - |
|
| 891 | - $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
| 892 | - |
|
| 893 | - if( ! $this->is_valid ){ |
|
| 894 | - |
|
| 895 | - // Keeping this compatible with Gravity Forms. |
|
| 896 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 897 | - $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 898 | - |
|
| 899 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 900 | - |
|
| 901 | - } else { |
|
| 902 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
| 906 | - * @since 1.5.4 |
|
| 907 | - * @param string $entry_updated_message Existing message |
|
| 908 | - * @param int $view_id View ID |
|
| 909 | - * @param array $entry Gravity Forms entry array |
|
| 910 | - * @param string $back_link URL to return to the original entry. @since 1.6 |
|
| 911 | - */ |
|
| 912 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 913 | - |
|
| 914 | - echo GVCommon::generate_notice( $message ); |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - } |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * Display the Edit Entry form in the original Gravity Forms format |
|
| 922 | - * |
|
| 923 | - * @since 1.9 |
|
| 924 | - * |
|
| 925 | - * @return void |
|
| 926 | - */ |
|
| 927 | - private function render_edit_form() { |
|
| 928 | - |
|
| 929 | - /** |
|
| 930 | - * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form |
|
| 931 | - * @since 1.17 |
|
| 932 | - * @param GravityView_Edit_Entry_Render $this |
|
| 933 | - */ |
|
| 934 | - do_action( 'gravityview/edit-entry/render/before', $this ); |
|
| 935 | - |
|
| 936 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 937 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 938 | - add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 939 | - |
|
| 940 | - add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); |
|
| 941 | - add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
| 942 | - |
|
| 943 | - // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
| 944 | - unset( $_GET['page'] ); |
|
| 945 | - |
|
| 946 | - // TODO: Verify multiple-page forms |
|
| 947 | - // TODO: Product fields are not editable |
|
| 948 | - |
|
| 949 | - ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic |
|
| 950 | - |
|
| 951 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 952 | - |
|
| 953 | - ob_get_clean(); |
|
| 954 | - |
|
| 955 | - remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 956 | - remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 957 | - remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 958 | - remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); |
|
| 959 | - remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
| 960 | - |
|
| 961 | - echo $html; |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form |
|
| 965 | - * @since 1.17 |
|
| 966 | - * @param GravityView_Edit_Entry_Render $this |
|
| 967 | - */ |
|
| 968 | - do_action( 'gravityview/edit-entry/render/after', $this ); |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
| 973 | - * @since 1.8 |
|
| 974 | - * @return string |
|
| 975 | - */ |
|
| 976 | - public function render_form_buttons() { |
|
| 977 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - |
|
| 981 | - /** |
|
| 982 | - * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
| 983 | - * |
|
| 984 | - * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
| 985 | - * |
|
| 986 | - * @param array $form |
|
| 987 | - * @param boolean $ajax Whether in AJAX mode |
|
| 988 | - * @param array|string $field_values Passed parameters to the form |
|
| 989 | - * |
|
| 990 | - * @since 1.9 |
|
| 991 | - * |
|
| 992 | - * @return array Modified form array |
|
| 993 | - */ |
|
| 994 | - public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
| 995 | - |
|
| 996 | - // In case we have validated the form, use it to inject the validation results into the form render |
|
| 997 | - if( isset( $this->form_after_validation ) ) { |
|
| 998 | - $form = $this->form_after_validation; |
|
| 999 | - } else { |
|
| 1000 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - $form = $this->filter_conditional_logic( $form ); |
|
| 1004 | - |
|
| 1005 | - $form = $this->prefill_conditional_logic( $form ); |
|
| 1006 | - |
|
| 1007 | - // for now we don't support Save and Continue feature. |
|
| 1008 | - if( ! self::$supports_save_and_continue ) { |
|
| 1009 | - unset( $form['save'] ); |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - return $form; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - /** |
|
| 1016 | - * 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. |
|
| 1017 | - * |
|
| 1018 | - * @since 1.16.2.2 |
|
| 1019 | - * |
|
| 1020 | - * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 1021 | - * @param GF_Field $field |
|
| 1022 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 1023 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 1024 | - * @param int $form_id Form ID |
|
| 1025 | - * |
|
| 1026 | - * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next) |
|
| 1027 | - */ |
|
| 1028 | - public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 1029 | - |
|
| 1030 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 1031 | - |
|
| 1032 | - $message = null; |
|
| 1033 | - |
|
| 1034 | - // First, make sure they have the capability to edit the post. |
|
| 1035 | - if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { |
|
| 1036 | - |
|
| 1037 | - /** |
|
| 1038 | - * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post |
|
| 1039 | - * @param string $message The existing "You don't have permission..." text |
|
| 1040 | - */ |
|
| 1041 | - $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); |
|
| 1042 | - |
|
| 1043 | - } elseif( null === get_post( $this->entry['post_id'] ) ) { |
|
| 1044 | - /** |
|
| 1045 | - * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists |
|
| 1046 | - * @param string $message The existing "This field is not editable; the post no longer exists." text |
|
| 1047 | - */ |
|
| 1048 | - $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - if( $message ) { |
|
| 1052 | - $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - return $field_content; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - /** |
|
| 1060 | - * |
|
| 1061 | - * Fill-in the saved values into the form inputs |
|
| 1062 | - * |
|
| 1063 | - * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 1064 | - * @param GF_Field $field |
|
| 1065 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 1066 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 1067 | - * @param int $form_id Form ID |
|
| 1068 | - * |
|
| 1069 | - * @return mixed |
|
| 1070 | - */ |
|
| 1071 | - public function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 1072 | - |
|
| 1073 | - $gv_field = GravityView_Fields::get_associated_field( $field ); |
|
| 1074 | - |
|
| 1075 | - // If the form has been submitted, then we don't need to pre-fill the values, |
|
| 1076 | - // Except for fileupload type and when a field input is overridden- run always!! |
|
| 1077 | - if( |
|
| 1078 | - ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 1079 | - && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) |
|
| 1080 | - || ! empty( $field_content ) |
|
| 1081 | - || in_array( $field->type, array( 'honeypot' ) ) |
|
| 1082 | - || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
| 1083 | - ) { |
|
| 1084 | - return $field_content; |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - // Turn on Admin-style display for file upload fields only |
|
| 1088 | - if( 'fileupload' === $field->type ) { |
|
| 1089 | - $_GET['page'] = 'gf_entries'; |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
| 1093 | - $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
| 1094 | - |
|
| 1095 | - // add categories as choices for Post Category field |
|
| 1096 | - if ( 'post_category' === $field->type ) { |
|
| 1097 | - $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - $field_value = $this->get_field_value( $field ); |
|
| 1101 | - |
|
| 1102 | - /** |
|
| 1103 | - * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 1104 | - * @since 1.11 |
|
| 1105 | - * @param mixed $field_value field value used to populate the input |
|
| 1106 | - * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 1107 | - */ |
|
| 1108 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type |
|
| 1112 | - * @since 1.17 |
|
| 1113 | - * @param mixed $field_value field value used to populate the input |
|
| 1114 | - * @param GF_Field $field Gravity Forms field object |
|
| 1115 | - */ |
|
| 1116 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field ); |
|
| 1117 | - |
|
| 1118 | - // Prevent any PHP warnings, like undefined index |
|
| 1119 | - ob_start(); |
|
| 1120 | - |
|
| 1121 | - /** @var GravityView_Field $gv_field */ |
|
| 1122 | - if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1123 | - $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
|
| 1124 | - } else { |
|
| 1125 | - $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - // If there was output, it's an error |
|
| 1130 | - $warnings = ob_get_clean(); |
|
| 1131 | - |
|
| 1132 | - if( !empty( $warnings ) ) { |
|
| 1133 | - do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - /** |
|
| 1137 | - * Unset hack $_GET['page'] = 'gf_entries' |
|
| 1138 | - * We need the fileupload html field to render with the proper id |
|
| 1139 | - * ( <li id="field_80_16" ... > ) |
|
| 1140 | - */ |
|
| 1141 | - unset( $_GET['page'] ); |
|
| 1142 | - |
|
| 1143 | - return $return; |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * Modify the value for the current field input |
|
| 1148 | - * |
|
| 1149 | - * @param GF_Field $field |
|
| 1150 | - * |
|
| 1151 | - * @return array|mixed|string|void |
|
| 1152 | - */ |
|
| 1153 | - private function get_field_value( $field ) { |
|
| 1154 | - |
|
| 1155 | - /** |
|
| 1156 | - * @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. |
|
| 1157 | - * @param boolean True: override saved values; False: don't override (default) |
|
| 1158 | - * @param $field GF_Field object Gravity Forms field object |
|
| 1159 | - * @since 1.13 |
|
| 1160 | - */ |
|
| 1161 | - $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
| 1162 | - |
|
| 1163 | - // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
| 1164 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1165 | - |
|
| 1166 | - $field_value = array(); |
|
| 1167 | - |
|
| 1168 | - // only accept pre-populated values if the field doesn't have any choice selected. |
|
| 1169 | - $allow_pre_populated = $field->allowsPrepopulate; |
|
| 1170 | - |
|
| 1171 | - foreach ( (array)$field->inputs as $input ) { |
|
| 1172 | - |
|
| 1173 | - $input_id = strval( $input['id'] ); |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * Display success or error message if the form has been submitted |
|
| 880 | + * |
|
| 881 | + * @uses GVCommon::generate_notice |
|
| 882 | + * |
|
| 883 | + * @since 1.16.2.2 |
|
| 884 | + * |
|
| 885 | + * @return void |
|
| 886 | + */ |
|
| 887 | + private function maybe_print_message() { |
|
| 888 | + |
|
| 889 | + if( rgpost('action') === 'update' ) { |
|
| 890 | + |
|
| 891 | + $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
| 892 | + |
|
| 893 | + if( ! $this->is_valid ){ |
|
| 894 | + |
|
| 895 | + // Keeping this compatible with Gravity Forms. |
|
| 896 | + $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 897 | + $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 898 | + |
|
| 899 | + echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 900 | + |
|
| 901 | + } else { |
|
| 902 | + $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
| 906 | + * @since 1.5.4 |
|
| 907 | + * @param string $entry_updated_message Existing message |
|
| 908 | + * @param int $view_id View ID |
|
| 909 | + * @param array $entry Gravity Forms entry array |
|
| 910 | + * @param string $back_link URL to return to the original entry. @since 1.6 |
|
| 911 | + */ |
|
| 912 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 913 | + |
|
| 914 | + echo GVCommon::generate_notice( $message ); |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * Display the Edit Entry form in the original Gravity Forms format |
|
| 922 | + * |
|
| 923 | + * @since 1.9 |
|
| 924 | + * |
|
| 925 | + * @return void |
|
| 926 | + */ |
|
| 927 | + private function render_edit_form() { |
|
| 928 | + |
|
| 929 | + /** |
|
| 930 | + * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form |
|
| 931 | + * @since 1.17 |
|
| 932 | + * @param GravityView_Edit_Entry_Render $this |
|
| 933 | + */ |
|
| 934 | + do_action( 'gravityview/edit-entry/render/before', $this ); |
|
| 935 | + |
|
| 936 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 937 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 938 | + add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 939 | + |
|
| 940 | + add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); |
|
| 941 | + add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
| 942 | + |
|
| 943 | + // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
| 944 | + unset( $_GET['page'] ); |
|
| 945 | + |
|
| 946 | + // TODO: Verify multiple-page forms |
|
| 947 | + // TODO: Product fields are not editable |
|
| 948 | + |
|
| 949 | + ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic |
|
| 950 | + |
|
| 951 | + $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 952 | + |
|
| 953 | + ob_get_clean(); |
|
| 954 | + |
|
| 955 | + remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 956 | + remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 957 | + remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 958 | + remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); |
|
| 959 | + remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
| 960 | + |
|
| 961 | + echo $html; |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form |
|
| 965 | + * @since 1.17 |
|
| 966 | + * @param GravityView_Edit_Entry_Render $this |
|
| 967 | + */ |
|
| 968 | + do_action( 'gravityview/edit-entry/render/after', $this ); |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
| 973 | + * @since 1.8 |
|
| 974 | + * @return string |
|
| 975 | + */ |
|
| 976 | + public function render_form_buttons() { |
|
| 977 | + return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + |
|
| 981 | + /** |
|
| 982 | + * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
| 983 | + * |
|
| 984 | + * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
| 985 | + * |
|
| 986 | + * @param array $form |
|
| 987 | + * @param boolean $ajax Whether in AJAX mode |
|
| 988 | + * @param array|string $field_values Passed parameters to the form |
|
| 989 | + * |
|
| 990 | + * @since 1.9 |
|
| 991 | + * |
|
| 992 | + * @return array Modified form array |
|
| 993 | + */ |
|
| 994 | + public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
| 995 | + |
|
| 996 | + // In case we have validated the form, use it to inject the validation results into the form render |
|
| 997 | + if( isset( $this->form_after_validation ) ) { |
|
| 998 | + $form = $this->form_after_validation; |
|
| 999 | + } else { |
|
| 1000 | + $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + $form = $this->filter_conditional_logic( $form ); |
|
| 1004 | + |
|
| 1005 | + $form = $this->prefill_conditional_logic( $form ); |
|
| 1006 | + |
|
| 1007 | + // for now we don't support Save and Continue feature. |
|
| 1008 | + if( ! self::$supports_save_and_continue ) { |
|
| 1009 | + unset( $form['save'] ); |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + return $form; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + /** |
|
| 1016 | + * 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. |
|
| 1017 | + * |
|
| 1018 | + * @since 1.16.2.2 |
|
| 1019 | + * |
|
| 1020 | + * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 1021 | + * @param GF_Field $field |
|
| 1022 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 1023 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 1024 | + * @param int $form_id Form ID |
|
| 1025 | + * |
|
| 1026 | + * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next) |
|
| 1027 | + */ |
|
| 1028 | + public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 1029 | + |
|
| 1030 | + if( GFCommon::is_post_field( $field ) ) { |
|
| 1031 | + |
|
| 1032 | + $message = null; |
|
| 1033 | + |
|
| 1034 | + // First, make sure they have the capability to edit the post. |
|
| 1035 | + if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { |
|
| 1036 | + |
|
| 1037 | + /** |
|
| 1038 | + * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post |
|
| 1039 | + * @param string $message The existing "You don't have permission..." text |
|
| 1040 | + */ |
|
| 1041 | + $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); |
|
| 1042 | + |
|
| 1043 | + } elseif( null === get_post( $this->entry['post_id'] ) ) { |
|
| 1044 | + /** |
|
| 1045 | + * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists |
|
| 1046 | + * @param string $message The existing "This field is not editable; the post no longer exists." text |
|
| 1047 | + */ |
|
| 1048 | + $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + if( $message ) { |
|
| 1052 | + $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return $field_content; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + /** |
|
| 1060 | + * |
|
| 1061 | + * Fill-in the saved values into the form inputs |
|
| 1062 | + * |
|
| 1063 | + * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 1064 | + * @param GF_Field $field |
|
| 1065 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 1066 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 1067 | + * @param int $form_id Form ID |
|
| 1068 | + * |
|
| 1069 | + * @return mixed |
|
| 1070 | + */ |
|
| 1071 | + public function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 1072 | + |
|
| 1073 | + $gv_field = GravityView_Fields::get_associated_field( $field ); |
|
| 1074 | + |
|
| 1075 | + // If the form has been submitted, then we don't need to pre-fill the values, |
|
| 1076 | + // Except for fileupload type and when a field input is overridden- run always!! |
|
| 1077 | + if( |
|
| 1078 | + ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 1079 | + && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) |
|
| 1080 | + || ! empty( $field_content ) |
|
| 1081 | + || in_array( $field->type, array( 'honeypot' ) ) |
|
| 1082 | + || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
| 1083 | + ) { |
|
| 1084 | + return $field_content; |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + // Turn on Admin-style display for file upload fields only |
|
| 1088 | + if( 'fileupload' === $field->type ) { |
|
| 1089 | + $_GET['page'] = 'gf_entries'; |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
| 1093 | + $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
| 1094 | + |
|
| 1095 | + // add categories as choices for Post Category field |
|
| 1096 | + if ( 'post_category' === $field->type ) { |
|
| 1097 | + $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + $field_value = $this->get_field_value( $field ); |
|
| 1101 | + |
|
| 1102 | + /** |
|
| 1103 | + * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 1104 | + * @since 1.11 |
|
| 1105 | + * @param mixed $field_value field value used to populate the input |
|
| 1106 | + * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 1107 | + */ |
|
| 1108 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type |
|
| 1112 | + * @since 1.17 |
|
| 1113 | + * @param mixed $field_value field value used to populate the input |
|
| 1114 | + * @param GF_Field $field Gravity Forms field object |
|
| 1115 | + */ |
|
| 1116 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field ); |
|
| 1117 | + |
|
| 1118 | + // Prevent any PHP warnings, like undefined index |
|
| 1119 | + ob_start(); |
|
| 1120 | + |
|
| 1121 | + /** @var GravityView_Field $gv_field */ |
|
| 1122 | + if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1123 | + $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
|
| 1124 | + } else { |
|
| 1125 | + $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + // If there was output, it's an error |
|
| 1130 | + $warnings = ob_get_clean(); |
|
| 1131 | + |
|
| 1132 | + if( !empty( $warnings ) ) { |
|
| 1133 | + do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + /** |
|
| 1137 | + * Unset hack $_GET['page'] = 'gf_entries' |
|
| 1138 | + * We need the fileupload html field to render with the proper id |
|
| 1139 | + * ( <li id="field_80_16" ... > ) |
|
| 1140 | + */ |
|
| 1141 | + unset( $_GET['page'] ); |
|
| 1142 | + |
|
| 1143 | + return $return; |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * Modify the value for the current field input |
|
| 1148 | + * |
|
| 1149 | + * @param GF_Field $field |
|
| 1150 | + * |
|
| 1151 | + * @return array|mixed|string|void |
|
| 1152 | + */ |
|
| 1153 | + private function get_field_value( $field ) { |
|
| 1154 | + |
|
| 1155 | + /** |
|
| 1156 | + * @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. |
|
| 1157 | + * @param boolean True: override saved values; False: don't override (default) |
|
| 1158 | + * @param $field GF_Field object Gravity Forms field object |
|
| 1159 | + * @since 1.13 |
|
| 1160 | + */ |
|
| 1161 | + $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
| 1162 | + |
|
| 1163 | + // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
| 1164 | + if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1165 | + |
|
| 1166 | + $field_value = array(); |
|
| 1167 | + |
|
| 1168 | + // only accept pre-populated values if the field doesn't have any choice selected. |
|
| 1169 | + $allow_pre_populated = $field->allowsPrepopulate; |
|
| 1170 | + |
|
| 1171 | + foreach ( (array)$field->inputs as $input ) { |
|
| 1172 | + |
|
| 1173 | + $input_id = strval( $input['id'] ); |
|
| 1174 | 1174 | |
| 1175 | - if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
|
| 1176 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1177 | - $allow_pre_populated = false; |
|
| 1178 | - } |
|
| 1175 | + if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
|
| 1176 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1177 | + $allow_pre_populated = false; |
|
| 1178 | + } |
|
| 1179 | 1179 | |
| 1180 | - } |
|
| 1180 | + } |
|
| 1181 | 1181 | |
| 1182 | - $pre_value = $field->get_value_submission( array(), false ); |
|
| 1182 | + $pre_value = $field->get_value_submission( array(), false ); |
|
| 1183 | 1183 | |
| 1184 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1184 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1185 | 1185 | |
| 1186 | - } else { |
|
| 1186 | + } else { |
|
| 1187 | 1187 | |
| 1188 | - $id = intval( $field->id ); |
|
| 1188 | + $id = intval( $field->id ); |
|
| 1189 | 1189 | |
| 1190 | - // get pre-populated value if exists |
|
| 1191 | - $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
| 1190 | + // get pre-populated value if exists |
|
| 1191 | + $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
| 1192 | 1192 | |
| 1193 | - // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
| 1194 | - // or pre-populated value if not empty and set to override saved value |
|
| 1195 | - $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1193 | + // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
| 1194 | + // or pre-populated value if not empty and set to override saved value |
|
| 1195 | + $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1196 | 1196 | |
| 1197 | - // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
| 1198 | - if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
|
| 1199 | - $categories = array(); |
|
| 1200 | - foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
| 1201 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1202 | - } |
|
| 1203 | - $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
| 1204 | - } |
|
| 1197 | + // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
| 1198 | + if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
|
| 1199 | + $categories = array(); |
|
| 1200 | + foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
| 1201 | + $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1202 | + } |
|
| 1203 | + $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | - } |
|
| 1206 | + } |
|
| 1207 | 1207 | |
| 1208 | - // if value is empty get the default value if defined |
|
| 1209 | - $field_value = $field->get_value_default_if_empty( $field_value ); |
|
| 1208 | + // if value is empty get the default value if defined |
|
| 1209 | + $field_value = $field->get_value_default_if_empty( $field_value ); |
|
| 1210 | 1210 | |
| 1211 | - return $field_value; |
|
| 1212 | - } |
|
| 1211 | + return $field_value; |
|
| 1212 | + } |
|
| 1213 | 1213 | |
| 1214 | 1214 | |
| 1215 | - // ---- Entry validation |
|
| 1215 | + // ---- Entry validation |
|
| 1216 | 1216 | |
| 1217 | - /** |
|
| 1218 | - * Add field keys that Gravity Forms expects. |
|
| 1219 | - * |
|
| 1220 | - * @see GFFormDisplay::validate() |
|
| 1221 | - * @param array $form GF Form |
|
| 1222 | - * @return array Modified GF Form |
|
| 1223 | - */ |
|
| 1224 | - public function gform_pre_validation( $form ) { |
|
| 1217 | + /** |
|
| 1218 | + * Add field keys that Gravity Forms expects. |
|
| 1219 | + * |
|
| 1220 | + * @see GFFormDisplay::validate() |
|
| 1221 | + * @param array $form GF Form |
|
| 1222 | + * @return array Modified GF Form |
|
| 1223 | + */ |
|
| 1224 | + public function gform_pre_validation( $form ) { |
|
| 1225 | 1225 | |
| 1226 | - if( ! $this->verify_nonce() ) { |
|
| 1227 | - return $form; |
|
| 1228 | - } |
|
| 1226 | + if( ! $this->verify_nonce() ) { |
|
| 1227 | + return $form; |
|
| 1228 | + } |
|
| 1229 | 1229 | |
| 1230 | - // Fix PHP warning regarding undefined index. |
|
| 1231 | - foreach ( $form['fields'] as &$field) { |
|
| 1230 | + // Fix PHP warning regarding undefined index. |
|
| 1231 | + foreach ( $form['fields'] as &$field) { |
|
| 1232 | 1232 | |
| 1233 | - // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
| 1234 | - // expects certain field array items to be set. |
|
| 1235 | - foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
| 1236 | - $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 1237 | - } |
|
| 1233 | + // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
| 1234 | + // expects certain field array items to be set. |
|
| 1235 | + foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
| 1236 | + $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 1237 | + } |
|
| 1238 | 1238 | |
| 1239 | - // unset emailConfirmEnabled for email type fields |
|
| 1240 | - /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
| 1239 | + // unset emailConfirmEnabled for email type fields |
|
| 1240 | + /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
| 1241 | 1241 | $field['emailConfirmEnabled'] = ''; |
| 1242 | 1242 | }*/ |
| 1243 | 1243 | |
| 1244 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 1244 | + switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 1245 | + |
|
| 1246 | + /** |
|
| 1247 | + * 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. |
|
| 1248 | + * |
|
| 1249 | + * 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. |
|
| 1250 | + * |
|
| 1251 | + * @hack |
|
| 1252 | + */ |
|
| 1253 | + case 'fileupload': |
|
| 1254 | + |
|
| 1255 | + // Set the previous value |
|
| 1256 | + $entry = $this->get_entry(); |
|
| 1245 | 1257 | |
| 1246 | - /** |
|
| 1247 | - * 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. |
|
| 1248 | - * |
|
| 1249 | - * 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. |
|
| 1250 | - * |
|
| 1251 | - * @hack |
|
| 1252 | - */ |
|
| 1253 | - case 'fileupload': |
|
| 1254 | - |
|
| 1255 | - // Set the previous value |
|
| 1256 | - $entry = $this->get_entry(); |
|
| 1257 | - |
|
| 1258 | - $input_name = 'input_'.$field->id; |
|
| 1259 | - $form_id = $form['id']; |
|
| 1260 | - |
|
| 1261 | - $value = NULL; |
|
| 1262 | - |
|
| 1263 | - // Use the previous entry value as the default. |
|
| 1264 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1265 | - $value = $entry[ $field->id ]; |
|
| 1266 | - } |
|
| 1258 | + $input_name = 'input_'.$field->id; |
|
| 1259 | + $form_id = $form['id']; |
|
| 1267 | 1260 | |
| 1268 | - // If this is a single upload file |
|
| 1269 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1270 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1271 | - $value = $file_path['url']; |
|
| 1261 | + $value = NULL; |
|
| 1272 | 1262 | |
| 1273 | - } else { |
|
| 1274 | - |
|
| 1275 | - // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 1276 | - // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 1277 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1278 | - |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - if( rgar($field, "multipleFiles") ) { |
|
| 1282 | - |
|
| 1283 | - // If there are fresh uploads, process and merge them. |
|
| 1284 | - // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 1285 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1286 | - $value = empty( $value ) ? '[]' : $value; |
|
| 1287 | - $value = stripslashes_deep( $value ); |
|
| 1288 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1289 | - } |
|
| 1263 | + // Use the previous entry value as the default. |
|
| 1264 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1265 | + $value = $entry[ $field->id ]; |
|
| 1266 | + } |
|
| 1290 | 1267 | |
| 1291 | - } else { |
|
| 1268 | + // If this is a single upload file |
|
| 1269 | + if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1270 | + $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1271 | + $value = $file_path['url']; |
|
| 1292 | 1272 | |
| 1293 | - // A file already exists when editing an entry |
|
| 1294 | - // We set this to solve issue when file upload fields are required. |
|
| 1295 | - GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 1273 | + } else { |
|
| 1296 | 1274 | |
| 1297 | - } |
|
| 1275 | + // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 1276 | + // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 1277 | + $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1298 | 1278 | |
| 1299 | - $this->entry[ $input_name ] = $value; |
|
| 1300 | - $_POST[ $input_name ] = $value; |
|
| 1279 | + } |
|
| 1301 | 1280 | |
| 1302 | - break; |
|
| 1281 | + if( rgar($field, "multipleFiles") ) { |
|
| 1303 | 1282 | |
| 1304 | - case 'number': |
|
| 1305 | - // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 1306 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1307 | - $_POST['input_'.$field->id ] = NULL; |
|
| 1308 | - } |
|
| 1309 | - break; |
|
| 1310 | - case 'captcha': |
|
| 1311 | - // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
| 1312 | - $_POST['recaptcha_challenge_field'] = NULL; |
|
| 1313 | - $_POST['recaptcha_response_field'] = NULL; |
|
| 1314 | - break; |
|
| 1315 | - } |
|
| 1283 | + // If there are fresh uploads, process and merge them. |
|
| 1284 | + // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 1285 | + if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1286 | + $value = empty( $value ) ? '[]' : $value; |
|
| 1287 | + $value = stripslashes_deep( $value ); |
|
| 1288 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1289 | + } |
|
| 1316 | 1290 | |
| 1317 | - } |
|
| 1291 | + } else { |
|
| 1318 | 1292 | |
| 1319 | - return $form; |
|
| 1320 | - } |
|
| 1293 | + // A file already exists when editing an entry |
|
| 1294 | + // We set this to solve issue when file upload fields are required. |
|
| 1295 | + GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 1321 | 1296 | |
| 1297 | + } |
|
| 1322 | 1298 | |
| 1323 | - /** |
|
| 1324 | - * Process validation for a edit entry submission |
|
| 1325 | - * |
|
| 1326 | - * Sets the `is_valid` object var |
|
| 1327 | - * |
|
| 1328 | - * @return void |
|
| 1329 | - */ |
|
| 1330 | - private function validate() { |
|
| 1299 | + $this->entry[ $input_name ] = $value; |
|
| 1300 | + $_POST[ $input_name ] = $value; |
|
| 1331 | 1301 | |
| 1332 | - /** |
|
| 1333 | - * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
| 1334 | - * GF User Registration Add-on version > 3.x has a different class name |
|
| 1335 | - * @since 1.16.2 |
|
| 1336 | - */ |
|
| 1337 | - if ( class_exists( 'GF_User_Registration' ) ) { |
|
| 1338 | - remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) ); |
|
| 1339 | - } else if ( class_exists( 'GFUser' ) ) { |
|
| 1340 | - remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
| 1341 | - } |
|
| 1302 | + break; |
|
| 1342 | 1303 | |
| 1304 | + case 'number': |
|
| 1305 | + // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 1306 | + if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1307 | + $_POST['input_'.$field->id ] = NULL; |
|
| 1308 | + } |
|
| 1309 | + break; |
|
| 1310 | + case 'captcha': |
|
| 1311 | + // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
| 1312 | + $_POST['recaptcha_challenge_field'] = NULL; |
|
| 1313 | + $_POST['recaptcha_response_field'] = NULL; |
|
| 1314 | + break; |
|
| 1315 | + } |
|
| 1343 | 1316 | |
| 1344 | - /** |
|
| 1345 | - * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
| 1346 | - * You can enter whatever you want! |
|
| 1347 | - * We try validating, and customize the results using `self::custom_validation()` |
|
| 1348 | - */ |
|
| 1349 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + return $form; |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + |
|
| 1323 | + /** |
|
| 1324 | + * Process validation for a edit entry submission |
|
| 1325 | + * |
|
| 1326 | + * Sets the `is_valid` object var |
|
| 1327 | + * |
|
| 1328 | + * @return void |
|
| 1329 | + */ |
|
| 1330 | + private function validate() { |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
| 1334 | + * GF User Registration Add-on version > 3.x has a different class name |
|
| 1335 | + * @since 1.16.2 |
|
| 1336 | + */ |
|
| 1337 | + if ( class_exists( 'GF_User_Registration' ) ) { |
|
| 1338 | + remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) ); |
|
| 1339 | + } else if ( class_exists( 'GFUser' ) ) { |
|
| 1340 | + remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
| 1341 | + } |
|
| 1350 | 1342 | |
| 1351 | - // Needed by the validate funtion |
|
| 1352 | - $failed_validation_page = NULL; |
|
| 1353 | - $field_values = RGForms::post( 'gform_field_values' ); |
|
| 1354 | 1343 | |
| 1355 | - // Prevent entry limit from running when editing an entry, also |
|
| 1356 | - // prevent form scheduling from preventing editing |
|
| 1357 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 1344 | + /** |
|
| 1345 | + * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
| 1346 | + * You can enter whatever you want! |
|
| 1347 | + * We try validating, and customize the results using `self::custom_validation()` |
|
| 1348 | + */ |
|
| 1349 | + add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 1358 | 1350 | |
| 1359 | - // Hide fields depending on Edit Entry settings |
|
| 1360 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1351 | + // Needed by the validate funtion |
|
| 1352 | + $failed_validation_page = NULL; |
|
| 1353 | + $field_values = RGForms::post( 'gform_field_values' ); |
|
| 1361 | 1354 | |
| 1362 | - $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
| 1355 | + // Prevent entry limit from running when editing an entry, also |
|
| 1356 | + // prevent form scheduling from preventing editing |
|
| 1357 | + unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 1363 | 1358 | |
| 1364 | - remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1365 | - } |
|
| 1359 | + // Hide fields depending on Edit Entry settings |
|
| 1360 | + $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1361 | + |
|
| 1362 | + $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
| 1363 | + |
|
| 1364 | + remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1365 | + } |
|
| 1366 | 1366 | |
| 1367 | 1367 | |
| 1368 | - /** |
|
| 1369 | - * Make validation work for Edit Entry |
|
| 1370 | - * |
|
| 1371 | - * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
| 1372 | - * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
| 1373 | - * fields. This goes through all the fields and if they're an invalid post field, we |
|
| 1374 | - * set them as valid. If there are still issues, we'll return false. |
|
| 1375 | - * |
|
| 1376 | - * @param [type] $validation_results [description] |
|
| 1377 | - * @return [type] [description] |
|
| 1378 | - */ |
|
| 1379 | - public function custom_validation( $validation_results ) { |
|
| 1368 | + /** |
|
| 1369 | + * Make validation work for Edit Entry |
|
| 1370 | + * |
|
| 1371 | + * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
| 1372 | + * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
| 1373 | + * fields. This goes through all the fields and if they're an invalid post field, we |
|
| 1374 | + * set them as valid. If there are still issues, we'll return false. |
|
| 1375 | + * |
|
| 1376 | + * @param [type] $validation_results [description] |
|
| 1377 | + * @return [type] [description] |
|
| 1378 | + */ |
|
| 1379 | + public function custom_validation( $validation_results ) { |
|
| 1380 | 1380 | |
| 1381 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1381 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1382 | 1382 | |
| 1383 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1383 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1384 | 1384 | |
| 1385 | - $gv_valid = true; |
|
| 1385 | + $gv_valid = true; |
|
| 1386 | 1386 | |
| 1387 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1387 | + foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1388 | 1388 | |
| 1389 | - $value = RGFormsModel::get_field_value( $field ); |
|
| 1390 | - $field_type = RGFormsModel::get_input_type( $field ); |
|
| 1389 | + $value = RGFormsModel::get_field_value( $field ); |
|
| 1390 | + $field_type = RGFormsModel::get_input_type( $field ); |
|
| 1391 | 1391 | |
| 1392 | - // Validate always |
|
| 1393 | - switch ( $field_type ) { |
|
| 1392 | + // Validate always |
|
| 1393 | + switch ( $field_type ) { |
|
| 1394 | 1394 | |
| 1395 | 1395 | |
| 1396 | - case 'fileupload' : |
|
| 1397 | - case 'post_image': |
|
| 1396 | + case 'fileupload' : |
|
| 1397 | + case 'post_image': |
|
| 1398 | 1398 | |
| 1399 | - // in case nothing is uploaded but there are already files saved |
|
| 1400 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1401 | - $field->failed_validation = false; |
|
| 1402 | - unset( $field->validation_message ); |
|
| 1403 | - } |
|
| 1399 | + // in case nothing is uploaded but there are already files saved |
|
| 1400 | + if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1401 | + $field->failed_validation = false; |
|
| 1402 | + unset( $field->validation_message ); |
|
| 1403 | + } |
|
| 1404 | 1404 | |
| 1405 | - // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1406 | - if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1405 | + // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1406 | + if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1407 | 1407 | |
| 1408 | - $input_name = 'input_' . $field->id; |
|
| 1409 | - //uploaded |
|
| 1410 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1408 | + $input_name = 'input_' . $field->id; |
|
| 1409 | + //uploaded |
|
| 1410 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1411 | 1411 | |
| 1412 | - //existent |
|
| 1413 | - $entry = $this->get_entry(); |
|
| 1414 | - $value = NULL; |
|
| 1415 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1416 | - $value = json_decode( $entry[ $field->id ], true ); |
|
| 1417 | - } |
|
| 1412 | + //existent |
|
| 1413 | + $entry = $this->get_entry(); |
|
| 1414 | + $value = NULL; |
|
| 1415 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1416 | + $value = json_decode( $entry[ $field->id ], true ); |
|
| 1417 | + } |
|
| 1418 | 1418 | |
| 1419 | - // count uploaded files and existent entry files |
|
| 1420 | - $count_files = count( $file_names ) + count( $value ); |
|
| 1419 | + // count uploaded files and existent entry files |
|
| 1420 | + $count_files = count( $file_names ) + count( $value ); |
|
| 1421 | 1421 | |
| 1422 | - if( $count_files > $field->maxFiles ) { |
|
| 1423 | - $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1424 | - $field->failed_validation = 1; |
|
| 1425 | - $gv_valid = false; |
|
| 1422 | + if( $count_files > $field->maxFiles ) { |
|
| 1423 | + $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1424 | + $field->failed_validation = 1; |
|
| 1425 | + $gv_valid = false; |
|
| 1426 | 1426 | |
| 1427 | - // in case of error make sure the newest upload files are removed from the upload input |
|
| 1428 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1429 | - } |
|
| 1427 | + // in case of error make sure the newest upload files are removed from the upload input |
|
| 1428 | + GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1429 | + } |
|
| 1430 | 1430 | |
| 1431 | - } |
|
| 1431 | + } |
|
| 1432 | 1432 | |
| 1433 | 1433 | |
| 1434 | - break; |
|
| 1434 | + break; |
|
| 1435 | 1435 | |
| 1436 | - } |
|
| 1436 | + } |
|
| 1437 | 1437 | |
| 1438 | - // This field has failed validation. |
|
| 1439 | - if( !empty( $field->failed_validation ) ) { |
|
| 1438 | + // This field has failed validation. |
|
| 1439 | + if( !empty( $field->failed_validation ) ) { |
|
| 1440 | 1440 | |
| 1441 | - do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
| 1441 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
| 1442 | 1442 | |
| 1443 | - switch ( $field_type ) { |
|
| 1443 | + switch ( $field_type ) { |
|
| 1444 | 1444 | |
| 1445 | - // Captchas don't need to be re-entered. |
|
| 1446 | - case 'captcha': |
|
| 1445 | + // Captchas don't need to be re-entered. |
|
| 1446 | + case 'captcha': |
|
| 1447 | 1447 | |
| 1448 | - // Post Image fields aren't editable, so we un-fail them. |
|
| 1449 | - case 'post_image': |
|
| 1450 | - $field->failed_validation = false; |
|
| 1451 | - unset( $field->validation_message ); |
|
| 1452 | - break; |
|
| 1448 | + // Post Image fields aren't editable, so we un-fail them. |
|
| 1449 | + case 'post_image': |
|
| 1450 | + $field->failed_validation = false; |
|
| 1451 | + unset( $field->validation_message ); |
|
| 1452 | + break; |
|
| 1453 | 1453 | |
| 1454 | - } |
|
| 1454 | + } |
|
| 1455 | 1455 | |
| 1456 | - // You can't continue inside a switch, so we do it after. |
|
| 1457 | - if( empty( $field->failed_validation ) ) { |
|
| 1458 | - continue; |
|
| 1459 | - } |
|
| 1456 | + // You can't continue inside a switch, so we do it after. |
|
| 1457 | + if( empty( $field->failed_validation ) ) { |
|
| 1458 | + continue; |
|
| 1459 | + } |
|
| 1460 | 1460 | |
| 1461 | - // checks if the No Duplicates option is not validating entry against itself, since |
|
| 1462 | - // we're editing a stored entry, it would also assume it's a duplicate. |
|
| 1463 | - if( !empty( $field->noDuplicates ) ) { |
|
| 1461 | + // checks if the No Duplicates option is not validating entry against itself, since |
|
| 1462 | + // we're editing a stored entry, it would also assume it's a duplicate. |
|
| 1463 | + if( !empty( $field->noDuplicates ) ) { |
|
| 1464 | 1464 | |
| 1465 | - $entry = $this->get_entry(); |
|
| 1465 | + $entry = $this->get_entry(); |
|
| 1466 | 1466 | |
| 1467 | - // If the value of the entry is the same as the stored value |
|
| 1468 | - // Then we can assume it's not a duplicate, it's the same. |
|
| 1469 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1470 | - //if value submitted was not changed, then don't validate |
|
| 1471 | - $field->failed_validation = false; |
|
| 1467 | + // If the value of the entry is the same as the stored value |
|
| 1468 | + // Then we can assume it's not a duplicate, it's the same. |
|
| 1469 | + if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1470 | + //if value submitted was not changed, then don't validate |
|
| 1471 | + $field->failed_validation = false; |
|
| 1472 | 1472 | |
| 1473 | - unset( $field->validation_message ); |
|
| 1473 | + unset( $field->validation_message ); |
|
| 1474 | 1474 | |
| 1475 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1475 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1476 | 1476 | |
| 1477 | - continue; |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1477 | + continue; |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | 1480 | |
| 1481 | - // if here then probably we are facing the validation 'At least one field must be filled out' |
|
| 1482 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1483 | - unset( $field->validation_message ); |
|
| 1484 | - $field->validation_message = false; |
|
| 1485 | - continue; |
|
| 1486 | - } |
|
| 1481 | + // if here then probably we are facing the validation 'At least one field must be filled out' |
|
| 1482 | + if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1483 | + unset( $field->validation_message ); |
|
| 1484 | + $field->validation_message = false; |
|
| 1485 | + continue; |
|
| 1486 | + } |
|
| 1487 | 1487 | |
| 1488 | - $gv_valid = false; |
|
| 1488 | + $gv_valid = false; |
|
| 1489 | 1489 | |
| 1490 | - } |
|
| 1490 | + } |
|
| 1491 | 1491 | |
| 1492 | - } |
|
| 1492 | + } |
|
| 1493 | 1493 | |
| 1494 | - $validation_results['is_valid'] = $gv_valid; |
|
| 1494 | + $validation_results['is_valid'] = $gv_valid; |
|
| 1495 | 1495 | |
| 1496 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1496 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1497 | 1497 | |
| 1498 | - // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
| 1499 | - $this->form_after_validation = $validation_results['form']; |
|
| 1498 | + // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
| 1499 | + $this->form_after_validation = $validation_results['form']; |
|
| 1500 | 1500 | |
| 1501 | - return $validation_results; |
|
| 1502 | - } |
|
| 1501 | + return $validation_results; |
|
| 1502 | + } |
|
| 1503 | 1503 | |
| 1504 | 1504 | |
| 1505 | - /** |
|
| 1506 | - * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
| 1507 | - * Get the current entry and set it if it's not yet set. |
|
| 1508 | - * @return array Gravity Forms entry array |
|
| 1509 | - */ |
|
| 1510 | - public function get_entry() { |
|
| 1505 | + /** |
|
| 1506 | + * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
| 1507 | + * Get the current entry and set it if it's not yet set. |
|
| 1508 | + * @return array Gravity Forms entry array |
|
| 1509 | + */ |
|
| 1510 | + public function get_entry() { |
|
| 1511 | 1511 | |
| 1512 | - if( empty( $this->entry ) ) { |
|
| 1513 | - // Get the database value of the entry that's being edited |
|
| 1514 | - $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
| 1515 | - } |
|
| 1512 | + if( empty( $this->entry ) ) { |
|
| 1513 | + // Get the database value of the entry that's being edited |
|
| 1514 | + $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
| 1515 | + } |
|
| 1516 | 1516 | |
| 1517 | - return $this->entry; |
|
| 1518 | - } |
|
| 1517 | + return $this->entry; |
|
| 1518 | + } |
|
| 1519 | 1519 | |
| 1520 | 1520 | |
| 1521 | 1521 | |
| 1522 | - // --- Filters |
|
| 1522 | + // --- Filters |
|
| 1523 | 1523 | |
| 1524 | - /** |
|
| 1525 | - * Get the Edit Entry fields as configured in the View |
|
| 1526 | - * |
|
| 1527 | - * @since 1.8 |
|
| 1528 | - * |
|
| 1529 | - * @param int $view_id |
|
| 1530 | - * |
|
| 1531 | - * @return array Array of fields that are configured in the Edit tab in the Admin |
|
| 1532 | - */ |
|
| 1533 | - private function get_configured_edit_fields( $form, $view_id ) { |
|
| 1524 | + /** |
|
| 1525 | + * Get the Edit Entry fields as configured in the View |
|
| 1526 | + * |
|
| 1527 | + * @since 1.8 |
|
| 1528 | + * |
|
| 1529 | + * @param int $view_id |
|
| 1530 | + * |
|
| 1531 | + * @return array Array of fields that are configured in the Edit tab in the Admin |
|
| 1532 | + */ |
|
| 1533 | + private function get_configured_edit_fields( $form, $view_id ) { |
|
| 1534 | 1534 | |
| 1535 | - // Get all fields for form |
|
| 1536 | - $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
| 1535 | + // Get all fields for form |
|
| 1536 | + $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
| 1537 | 1537 | |
| 1538 | - // If edit tab not yet configured, show all fields |
|
| 1539 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1538 | + // If edit tab not yet configured, show all fields |
|
| 1539 | + $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1540 | 1540 | |
| 1541 | - // Show hidden fields as text fields |
|
| 1542 | - $form = $this->fix_survey_fields( $form ); |
|
| 1541 | + // Show hidden fields as text fields |
|
| 1542 | + $form = $this->fix_survey_fields( $form ); |
|
| 1543 | 1543 | |
| 1544 | - // Hide fields depending on admin settings |
|
| 1545 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1544 | + // Hide fields depending on admin settings |
|
| 1545 | + $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1546 | 1546 | |
| 1547 | - // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1548 | - $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1547 | + // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1548 | + $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1549 | 1549 | |
| 1550 | - /** |
|
| 1551 | - * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form |
|
| 1552 | - * @since 1.17 |
|
| 1553 | - * @param GF_Field[] $fields Gravity Forms form fields |
|
| 1554 | - * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1555 | - * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry) |
|
| 1556 | - * @param int $view_id View ID |
|
| 1557 | - */ |
|
| 1558 | - $fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id ); |
|
| 1550 | + /** |
|
| 1551 | + * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form |
|
| 1552 | + * @since 1.17 |
|
| 1553 | + * @param GF_Field[] $fields Gravity Forms form fields |
|
| 1554 | + * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1555 | + * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry) |
|
| 1556 | + * @param int $view_id View ID |
|
| 1557 | + */ |
|
| 1558 | + $fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id ); |
|
| 1559 | 1559 | |
| 1560 | - return $fields; |
|
| 1561 | - } |
|
| 1560 | + return $fields; |
|
| 1561 | + } |
|
| 1562 | 1562 | |
| 1563 | - /** |
|
| 1564 | - * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in |
|
| 1565 | - * |
|
| 1566 | - * @since 1.16.4 |
|
| 1567 | - * |
|
| 1568 | - * @param array $form |
|
| 1569 | - * |
|
| 1570 | - * @return array Form, with all fields set to `allowsPrepopulate => true` |
|
| 1571 | - */ |
|
| 1572 | - private function fix_survey_fields( $form ) { |
|
| 1563 | + /** |
|
| 1564 | + * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in |
|
| 1565 | + * |
|
| 1566 | + * @since 1.16.4 |
|
| 1567 | + * |
|
| 1568 | + * @param array $form |
|
| 1569 | + * |
|
| 1570 | + * @return array Form, with all fields set to `allowsPrepopulate => true` |
|
| 1571 | + */ |
|
| 1572 | + private function fix_survey_fields( $form ) { |
|
| 1573 | 1573 | |
| 1574 | - /** @var GF_Field $field */ |
|
| 1575 | - foreach( $form['fields'] as &$field ) { |
|
| 1576 | - $field->allowsPrepopulate = true; |
|
| 1577 | - } |
|
| 1574 | + /** @var GF_Field $field */ |
|
| 1575 | + foreach( $form['fields'] as &$field ) { |
|
| 1576 | + $field->allowsPrepopulate = true; |
|
| 1577 | + } |
|
| 1578 | 1578 | |
| 1579 | - return $form; |
|
| 1580 | - } |
|
| 1579 | + return $form; |
|
| 1580 | + } |
|
| 1581 | 1581 | |
| 1582 | 1582 | |
| 1583 | - /** |
|
| 1584 | - * Filter area fields based on specified conditions |
|
| 1585 | - * - This filter removes the fields that have calculation configured |
|
| 1586 | - * |
|
| 1587 | - * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
| 1588 | - * @access private |
|
| 1589 | - * @param GF_Field[] $fields |
|
| 1590 | - * @param array $configured_fields |
|
| 1591 | - * @since 1.5 |
|
| 1592 | - * @return array $fields |
|
| 1593 | - */ |
|
| 1594 | - private function filter_fields( $fields, $configured_fields ) { |
|
| 1595 | - |
|
| 1596 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1597 | - return $fields; |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - $edit_fields = array(); |
|
| 1601 | - |
|
| 1602 | - $field_type_blacklist = array( |
|
| 1603 | - 'page', |
|
| 1604 | - ); |
|
| 1605 | - |
|
| 1606 | - /** |
|
| 1607 | - * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
| 1608 | - * @since 1.9.1 |
|
| 1609 | - * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
| 1610 | - */ |
|
| 1611 | - $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
| 1612 | - |
|
| 1613 | - if( $hide_product_fields ) { |
|
| 1614 | - $field_type_blacklist[] = 'option'; |
|
| 1615 | - $field_type_blacklist[] = 'quantity'; |
|
| 1616 | - $field_type_blacklist[] = 'product'; |
|
| 1617 | - $field_type_blacklist[] = 'total'; |
|
| 1618 | - $field_type_blacklist[] = 'shipping'; |
|
| 1619 | - $field_type_blacklist[] = 'calculation'; |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - // First, remove blacklist or calculation fields |
|
| 1623 | - foreach ( $fields as $key => $field ) { |
|
| 1624 | - |
|
| 1625 | - // Remove the fields that have calculation properties and keep them to be used later |
|
| 1626 | - // @since 1.16.2 |
|
| 1627 | - if( $field->has_calculation() ) { |
|
| 1628 | - $this->fields_with_calculation[] = $field; |
|
| 1629 | - // don't remove the calculation fields on form render. |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - // process total field after all fields have been saved |
|
| 1633 | - if ( $field->type == 'total' ) { |
|
| 1634 | - $this->total_fields[] = $field; |
|
| 1635 | - unset( $fields[ $key ] ); |
|
| 1636 | - } |
|
| 1637 | - |
|
| 1638 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1639 | - unset( $fields[ $key ] ); |
|
| 1640 | - } |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - // The Edit tab has not been configured, so we return all fields by default. |
|
| 1644 | - if( empty( $configured_fields ) ) { |
|
| 1645 | - return $fields; |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - // The edit tab has been configured, so we loop through to configured settings |
|
| 1649 | - foreach ( $configured_fields as $configured_field ) { |
|
| 1650 | - |
|
| 1651 | - /** @var GF_Field $field */ |
|
| 1652 | - foreach ( $fields as $field ) { |
|
| 1653 | - |
|
| 1654 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1655 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1656 | - break; |
|
| 1657 | - } |
|
| 1658 | - |
|
| 1659 | - } |
|
| 1660 | - |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - return $edit_fields; |
|
| 1664 | - |
|
| 1665 | - } |
|
| 1666 | - |
|
| 1667 | - /** |
|
| 1668 | - * Override GF Form field properties with the ones defined on the View |
|
| 1669 | - * @param GF_Field $field GF Form field object |
|
| 1670 | - * @param array $field_setting GV field options |
|
| 1671 | - * @since 1.5 |
|
| 1672 | - * @return array|GF_Field |
|
| 1673 | - */ |
|
| 1674 | - private function merge_field_properties( $field, $field_setting ) { |
|
| 1675 | - |
|
| 1676 | - $return_field = $field; |
|
| 1677 | - |
|
| 1678 | - if( empty( $field_setting['show_label'] ) ) { |
|
| 1679 | - $return_field->label = ''; |
|
| 1680 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1681 | - $return_field->label = $field_setting['custom_label']; |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1685 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1686 | - } |
|
| 1687 | - |
|
| 1688 | - /** |
|
| 1689 | - * Normalize page numbers - avoid conflicts with page validation |
|
| 1690 | - * @since 1.6 |
|
| 1691 | - */ |
|
| 1692 | - $return_field->pageNumber = 1; |
|
| 1693 | - |
|
| 1694 | - return $return_field; |
|
| 1695 | - |
|
| 1696 | - } |
|
| 1697 | - |
|
| 1698 | - /** |
|
| 1699 | - * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
| 1700 | - * |
|
| 1701 | - * @since 1.9.1 |
|
| 1702 | - * |
|
| 1703 | - * @param array|GF_Field[] $fields Gravity Forms form fields |
|
| 1704 | - * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1705 | - * @param array $form GF Form array |
|
| 1706 | - * @param int $view_id View ID |
|
| 1707 | - * |
|
| 1708 | - * @return array Possibly modified form array |
|
| 1709 | - */ |
|
| 1710 | - private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * @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 |
|
| 1714 | - * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1715 | - * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1716 | - * @since 1.9.1 |
|
| 1717 | - * @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. |
|
| 1718 | - * @param array $form GF Form array |
|
| 1719 | - * @param int $view_id View ID |
|
| 1720 | - */ |
|
| 1721 | - $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1722 | - |
|
| 1723 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1724 | - foreach( $fields as $k => $field ) { |
|
| 1725 | - if( $field->adminOnly ) { |
|
| 1726 | - unset( $fields[ $k ] ); |
|
| 1727 | - } |
|
| 1728 | - } |
|
| 1729 | - return $fields; |
|
| 1730 | - } |
|
| 1731 | - |
|
| 1732 | - foreach( $fields as &$field ) { |
|
| 1733 | - $field->adminOnly = false; |
|
| 1734 | - } |
|
| 1735 | - |
|
| 1736 | - return $fields; |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - // --- Conditional Logic |
|
| 1740 | - |
|
| 1741 | - /** |
|
| 1742 | - * Conditional logic isn't designed to work with forms that already have content. When switching input values, |
|
| 1743 | - * the dependent fields will be blank. |
|
| 1744 | - * |
|
| 1745 | - * Note: This is because GF populates a JavaScript variable with the input values. This is tough to filter at the input level; |
|
| 1746 | - * via the `gform_field_value` filter; it requires lots of legwork. Doing it at the form level is easier. |
|
| 1747 | - * |
|
| 1748 | - * @since 1.17.4 |
|
| 1749 | - * |
|
| 1750 | - * @param array $form Gravity Forms array object |
|
| 1751 | - * |
|
| 1752 | - * @return array $form, modified to fix conditional |
|
| 1753 | - */ |
|
| 1754 | - function prefill_conditional_logic( $form ) { |
|
| 1755 | - |
|
| 1756 | - if( ! GFFormDisplay::has_conditional_logic( $form ) ) { |
|
| 1757 | - return $form; |
|
| 1758 | - } |
|
| 1759 | - |
|
| 1760 | - // Have Conditional Logic pre-fill fields as if the data were default values |
|
| 1761 | - /** @var GF_Field $field */ |
|
| 1762 | - foreach ( $form['fields'] as &$field ) { |
|
| 1763 | - |
|
| 1764 | - if( 'checkbox' === $field->type ) { |
|
| 1765 | - foreach ( $field->get_entry_inputs() as $key => $input ) { |
|
| 1766 | - $input_id = $input['id']; |
|
| 1767 | - $choice = $field->choices[ $key ]; |
|
| 1768 | - $value = rgar( $this->entry, $input_id ); |
|
| 1769 | - $match = RGFormsModel::choice_value_match( $field, $choice, $value ); |
|
| 1770 | - if( $match ) { |
|
| 1771 | - $field->choices[ $key ]['isSelected'] = true; |
|
| 1772 | - } |
|
| 1773 | - } |
|
| 1774 | - } else { |
|
| 1775 | - |
|
| 1776 | - // We need to run through each field to set the default values |
|
| 1777 | - foreach ( $this->entry as $field_id => $field_value ) { |
|
| 1778 | - |
|
| 1779 | - if( floatval( $field_id ) === floatval( $field->id ) ) { |
|
| 1780 | - |
|
| 1781 | - if( 'list' === $field->type ) { |
|
| 1782 | - $list_rows = maybe_unserialize( $field_value ); |
|
| 1783 | - |
|
| 1784 | - $list_field_value = array(); |
|
| 1785 | - foreach ( $list_rows as $row ) { |
|
| 1786 | - foreach ( $row as $column ) { |
|
| 1787 | - $list_field_value[] = $column; |
|
| 1788 | - } |
|
| 1789 | - } |
|
| 1790 | - |
|
| 1791 | - $field->defaultValue = $list_field_value; |
|
| 1792 | - } else { |
|
| 1793 | - $field->defaultValue = $field_value; |
|
| 1794 | - } |
|
| 1795 | - } |
|
| 1796 | - } |
|
| 1797 | - } |
|
| 1798 | - } |
|
| 1799 | - |
|
| 1800 | - return $form; |
|
| 1801 | - } |
|
| 1802 | - |
|
| 1803 | - /** |
|
| 1804 | - * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
| 1805 | - * |
|
| 1806 | - * @todo Merge with caller method |
|
| 1807 | - * @since 1.9 |
|
| 1808 | - * |
|
| 1809 | - * @param array $form Gravity Forms form |
|
| 1810 | - * @return array Modified form, if not using Conditional Logic |
|
| 1811 | - */ |
|
| 1812 | - private function filter_conditional_logic( $form ) { |
|
| 1813 | - |
|
| 1814 | - /** |
|
| 1815 | - * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
| 1816 | - * @since 1.9 |
|
| 1817 | - * @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 |
|
| 1818 | - * @param array $form Gravity Forms form |
|
| 1819 | - */ |
|
| 1820 | - $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
| 1821 | - |
|
| 1822 | - if( $use_conditional_logic ) { |
|
| 1823 | - return $form; |
|
| 1824 | - } |
|
| 1825 | - |
|
| 1826 | - foreach( $form['fields'] as &$field ) { |
|
| 1827 | - /* @var GF_Field $field */ |
|
| 1828 | - $field->conditionalLogic = null; |
|
| 1829 | - } |
|
| 1830 | - |
|
| 1831 | - unset( $form['button']['conditionalLogic'] ); |
|
| 1832 | - |
|
| 1833 | - return $form; |
|
| 1834 | - |
|
| 1835 | - } |
|
| 1836 | - |
|
| 1837 | - /** |
|
| 1838 | - * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
| 1839 | - * |
|
| 1840 | - * @since 1.9 |
|
| 1841 | - * |
|
| 1842 | - * @param $has_conditional_logic |
|
| 1843 | - * @param $form |
|
| 1844 | - * @return mixed|void |
|
| 1845 | - */ |
|
| 1846 | - public function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
| 1847 | - |
|
| 1848 | - if( ! $this->is_edit_entry() ) { |
|
| 1849 | - return $has_conditional_logic; |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */ |
|
| 1853 | - return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
| 1854 | - } |
|
| 1855 | - |
|
| 1856 | - |
|
| 1857 | - // --- User checks and nonces |
|
| 1858 | - |
|
| 1859 | - /** |
|
| 1860 | - * Check if the user can edit the entry |
|
| 1861 | - * |
|
| 1862 | - * - Is the nonce valid? |
|
| 1863 | - * - Does the user have the right caps for the entry |
|
| 1864 | - * - Is the entry in the trash? |
|
| 1865 | - * |
|
| 1866 | - * @todo Move to GVCommon |
|
| 1867 | - * |
|
| 1868 | - * @param boolean $echo Show error messages in the form? |
|
| 1869 | - * @return boolean True: can edit form. False: nope. |
|
| 1870 | - */ |
|
| 1871 | - private function user_can_edit_entry( $echo = false ) { |
|
| 1872 | - |
|
| 1873 | - $error = NULL; |
|
| 1874 | - |
|
| 1875 | - /** |
|
| 1876 | - * 1. Permalinks are turned off |
|
| 1877 | - * 2. There are two entries embedded using oEmbed |
|
| 1878 | - * 3. One of the entries has just been saved |
|
| 1879 | - */ |
|
| 1880 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1881 | - |
|
| 1882 | - $error = true; |
|
| 1883 | - |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1887 | - |
|
| 1888 | - $error = true; |
|
| 1889 | - |
|
| 1890 | - } elseif( ! $this->verify_nonce() ) { |
|
| 1891 | - |
|
| 1892 | - /** |
|
| 1893 | - * If the Entry is embedded, there may be two entries on the same page. |
|
| 1894 | - * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
| 1895 | - */ |
|
| 1896 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1897 | - $error = true; |
|
| 1898 | - } else { |
|
| 1899 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1900 | - } |
|
| 1901 | - |
|
| 1902 | - } |
|
| 1903 | - |
|
| 1904 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1905 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1906 | - } |
|
| 1907 | - |
|
| 1908 | - if( $this->entry['status'] === 'trash' ) { |
|
| 1909 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1910 | - } |
|
| 1583 | + /** |
|
| 1584 | + * Filter area fields based on specified conditions |
|
| 1585 | + * - This filter removes the fields that have calculation configured |
|
| 1586 | + * |
|
| 1587 | + * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
| 1588 | + * @access private |
|
| 1589 | + * @param GF_Field[] $fields |
|
| 1590 | + * @param array $configured_fields |
|
| 1591 | + * @since 1.5 |
|
| 1592 | + * @return array $fields |
|
| 1593 | + */ |
|
| 1594 | + private function filter_fields( $fields, $configured_fields ) { |
|
| 1595 | + |
|
| 1596 | + if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1597 | + return $fields; |
|
| 1598 | + } |
|
| 1911 | 1599 | |
| 1912 | - // No errors; everything's fine here! |
|
| 1913 | - if( empty( $error ) ) { |
|
| 1914 | - return true; |
|
| 1915 | - } |
|
| 1600 | + $edit_fields = array(); |
|
| 1916 | 1601 | |
| 1917 | - if( $echo && $error !== true ) { |
|
| 1602 | + $field_type_blacklist = array( |
|
| 1603 | + 'page', |
|
| 1604 | + ); |
|
| 1918 | 1605 | |
| 1919 | - $error = esc_html( $error ); |
|
| 1606 | + /** |
|
| 1607 | + * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
| 1608 | + * @since 1.9.1 |
|
| 1609 | + * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
| 1610 | + */ |
|
| 1611 | + $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
| 1920 | 1612 | |
| 1921 | - /** |
|
| 1922 | - * @since 1.9 |
|
| 1923 | - */ |
|
| 1924 | - if ( ! empty( $this->entry ) ) { |
|
| 1925 | - $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;" ) ); |
|
| 1926 | - } |
|
| 1613 | + if( $hide_product_fields ) { |
|
| 1614 | + $field_type_blacklist[] = 'option'; |
|
| 1615 | + $field_type_blacklist[] = 'quantity'; |
|
| 1616 | + $field_type_blacklist[] = 'product'; |
|
| 1617 | + $field_type_blacklist[] = 'total'; |
|
| 1618 | + $field_type_blacklist[] = 'shipping'; |
|
| 1619 | + $field_type_blacklist[] = 'calculation'; |
|
| 1620 | + } |
|
| 1927 | 1621 | |
| 1928 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1929 | - } |
|
| 1622 | + // First, remove blacklist or calculation fields |
|
| 1623 | + foreach ( $fields as $key => $field ) { |
|
| 1930 | 1624 | |
| 1931 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1625 | + // Remove the fields that have calculation properties and keep them to be used later |
|
| 1626 | + // @since 1.16.2 |
|
| 1627 | + if( $field->has_calculation() ) { |
|
| 1628 | + $this->fields_with_calculation[] = $field; |
|
| 1629 | + // don't remove the calculation fields on form render. |
|
| 1630 | + } |
|
| 1932 | 1631 | |
| 1933 | - return false; |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - |
|
| 1937 | - /** |
|
| 1938 | - * Check whether a field is editable by the current user, and optionally display an error message |
|
| 1939 | - * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
| 1940 | - * @param array $field Field or field settings array |
|
| 1941 | - * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
| 1942 | - * @return boolean True: user can edit the current field; False: nope, they can't. |
|
| 1943 | - */ |
|
| 1944 | - private function user_can_edit_field( $field, $echo = false ) { |
|
| 1632 | + // process total field after all fields have been saved |
|
| 1633 | + if ( $field->type == 'total' ) { |
|
| 1634 | + $this->total_fields[] = $field; |
|
| 1635 | + unset( $fields[ $key ] ); |
|
| 1636 | + } |
|
| 1945 | 1637 | |
| 1946 | - $error = NULL; |
|
| 1638 | + if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1639 | + unset( $fields[ $key ] ); |
|
| 1640 | + } |
|
| 1641 | + } |
|
| 1947 | 1642 | |
| 1948 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1949 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1950 | - } |
|
| 1643 | + // The Edit tab has not been configured, so we return all fields by default. |
|
| 1644 | + if( empty( $configured_fields ) ) { |
|
| 1645 | + return $fields; |
|
| 1646 | + } |
|
| 1951 | 1647 | |
| 1952 | - // No errors; everything's fine here! |
|
| 1953 | - if( empty( $error ) ) { |
|
| 1954 | - return true; |
|
| 1955 | - } |
|
| 1648 | + // The edit tab has been configured, so we loop through to configured settings |
|
| 1649 | + foreach ( $configured_fields as $configured_field ) { |
|
| 1956 | 1650 | |
| 1957 | - if( $echo ) { |
|
| 1958 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1651 | + /** @var GF_Field $field */ |
|
| 1652 | + foreach ( $fields as $field ) { |
|
| 1962 | 1653 | |
| 1963 | - return false; |
|
| 1654 | + if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1655 | + $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1656 | + break; |
|
| 1657 | + } |
|
| 1964 | 1658 | |
| 1965 | - } |
|
| 1659 | + } |
|
| 1966 | 1660 | |
| 1661 | + } |
|
| 1967 | 1662 | |
| 1968 | - /** |
|
| 1969 | - * checks if user has permissions to edit a specific field |
|
| 1970 | - * |
|
| 1971 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
| 1972 | - * |
|
| 1973 | - * @param [type] $field [description] |
|
| 1974 | - * @return bool |
|
| 1975 | - */ |
|
| 1976 | - private function check_user_cap_edit_field( $field ) { |
|
| 1663 | + return $edit_fields; |
|
| 1977 | 1664 | |
| 1978 | - // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
| 1979 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1980 | - return true; |
|
| 1981 | - } |
|
| 1665 | + } |
|
| 1666 | + |
|
| 1667 | + /** |
|
| 1668 | + * Override GF Form field properties with the ones defined on the View |
|
| 1669 | + * @param GF_Field $field GF Form field object |
|
| 1670 | + * @param array $field_setting GV field options |
|
| 1671 | + * @since 1.5 |
|
| 1672 | + * @return array|GF_Field |
|
| 1673 | + */ |
|
| 1674 | + private function merge_field_properties( $field, $field_setting ) { |
|
| 1675 | + |
|
| 1676 | + $return_field = $field; |
|
| 1677 | + |
|
| 1678 | + if( empty( $field_setting['show_label'] ) ) { |
|
| 1679 | + $return_field->label = ''; |
|
| 1680 | + } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1681 | + $return_field->label = $field_setting['custom_label']; |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1685 | + $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1686 | + } |
|
| 1687 | + |
|
| 1688 | + /** |
|
| 1689 | + * Normalize page numbers - avoid conflicts with page validation |
|
| 1690 | + * @since 1.6 |
|
| 1691 | + */ |
|
| 1692 | + $return_field->pageNumber = 1; |
|
| 1693 | + |
|
| 1694 | + return $return_field; |
|
| 1695 | + |
|
| 1696 | + } |
|
| 1697 | + |
|
| 1698 | + /** |
|
| 1699 | + * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
| 1700 | + * |
|
| 1701 | + * @since 1.9.1 |
|
| 1702 | + * |
|
| 1703 | + * @param array|GF_Field[] $fields Gravity Forms form fields |
|
| 1704 | + * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1705 | + * @param array $form GF Form array |
|
| 1706 | + * @param int $view_id View ID |
|
| 1707 | + * |
|
| 1708 | + * @return array Possibly modified form array |
|
| 1709 | + */ |
|
| 1710 | + private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * @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 |
|
| 1714 | + * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1715 | + * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1716 | + * @since 1.9.1 |
|
| 1717 | + * @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. |
|
| 1718 | + * @param array $form GF Form array |
|
| 1719 | + * @param int $view_id View ID |
|
| 1720 | + */ |
|
| 1721 | + $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1722 | + |
|
| 1723 | + if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1724 | + foreach( $fields as $k => $field ) { |
|
| 1725 | + if( $field->adminOnly ) { |
|
| 1726 | + unset( $fields[ $k ] ); |
|
| 1727 | + } |
|
| 1728 | + } |
|
| 1729 | + return $fields; |
|
| 1730 | + } |
|
| 1731 | + |
|
| 1732 | + foreach( $fields as &$field ) { |
|
| 1733 | + $field->adminOnly = false; |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + return $fields; |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + // --- Conditional Logic |
|
| 1740 | + |
|
| 1741 | + /** |
|
| 1742 | + * Conditional logic isn't designed to work with forms that already have content. When switching input values, |
|
| 1743 | + * the dependent fields will be blank. |
|
| 1744 | + * |
|
| 1745 | + * Note: This is because GF populates a JavaScript variable with the input values. This is tough to filter at the input level; |
|
| 1746 | + * via the `gform_field_value` filter; it requires lots of legwork. Doing it at the form level is easier. |
|
| 1747 | + * |
|
| 1748 | + * @since 1.17.4 |
|
| 1749 | + * |
|
| 1750 | + * @param array $form Gravity Forms array object |
|
| 1751 | + * |
|
| 1752 | + * @return array $form, modified to fix conditional |
|
| 1753 | + */ |
|
| 1754 | + function prefill_conditional_logic( $form ) { |
|
| 1755 | + |
|
| 1756 | + if( ! GFFormDisplay::has_conditional_logic( $form ) ) { |
|
| 1757 | + return $form; |
|
| 1758 | + } |
|
| 1759 | + |
|
| 1760 | + // Have Conditional Logic pre-fill fields as if the data were default values |
|
| 1761 | + /** @var GF_Field $field */ |
|
| 1762 | + foreach ( $form['fields'] as &$field ) { |
|
| 1763 | + |
|
| 1764 | + if( 'checkbox' === $field->type ) { |
|
| 1765 | + foreach ( $field->get_entry_inputs() as $key => $input ) { |
|
| 1766 | + $input_id = $input['id']; |
|
| 1767 | + $choice = $field->choices[ $key ]; |
|
| 1768 | + $value = rgar( $this->entry, $input_id ); |
|
| 1769 | + $match = RGFormsModel::choice_value_match( $field, $choice, $value ); |
|
| 1770 | + if( $match ) { |
|
| 1771 | + $field->choices[ $key ]['isSelected'] = true; |
|
| 1772 | + } |
|
| 1773 | + } |
|
| 1774 | + } else { |
|
| 1775 | + |
|
| 1776 | + // We need to run through each field to set the default values |
|
| 1777 | + foreach ( $this->entry as $field_id => $field_value ) { |
|
| 1778 | + |
|
| 1779 | + if( floatval( $field_id ) === floatval( $field->id ) ) { |
|
| 1780 | + |
|
| 1781 | + if( 'list' === $field->type ) { |
|
| 1782 | + $list_rows = maybe_unserialize( $field_value ); |
|
| 1783 | + |
|
| 1784 | + $list_field_value = array(); |
|
| 1785 | + foreach ( $list_rows as $row ) { |
|
| 1786 | + foreach ( $row as $column ) { |
|
| 1787 | + $list_field_value[] = $column; |
|
| 1788 | + } |
|
| 1789 | + } |
|
| 1790 | + |
|
| 1791 | + $field->defaultValue = $list_field_value; |
|
| 1792 | + } else { |
|
| 1793 | + $field->defaultValue = $field_value; |
|
| 1794 | + } |
|
| 1795 | + } |
|
| 1796 | + } |
|
| 1797 | + } |
|
| 1798 | + } |
|
| 1799 | + |
|
| 1800 | + return $form; |
|
| 1801 | + } |
|
| 1802 | + |
|
| 1803 | + /** |
|
| 1804 | + * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
| 1805 | + * |
|
| 1806 | + * @todo Merge with caller method |
|
| 1807 | + * @since 1.9 |
|
| 1808 | + * |
|
| 1809 | + * @param array $form Gravity Forms form |
|
| 1810 | + * @return array Modified form, if not using Conditional Logic |
|
| 1811 | + */ |
|
| 1812 | + private function filter_conditional_logic( $form ) { |
|
| 1813 | + |
|
| 1814 | + /** |
|
| 1815 | + * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
| 1816 | + * @since 1.9 |
|
| 1817 | + * @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 |
|
| 1818 | + * @param array $form Gravity Forms form |
|
| 1819 | + */ |
|
| 1820 | + $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
| 1821 | + |
|
| 1822 | + if( $use_conditional_logic ) { |
|
| 1823 | + return $form; |
|
| 1824 | + } |
|
| 1825 | + |
|
| 1826 | + foreach( $form['fields'] as &$field ) { |
|
| 1827 | + /* @var GF_Field $field */ |
|
| 1828 | + $field->conditionalLogic = null; |
|
| 1829 | + } |
|
| 1830 | + |
|
| 1831 | + unset( $form['button']['conditionalLogic'] ); |
|
| 1832 | + |
|
| 1833 | + return $form; |
|
| 1834 | + |
|
| 1835 | + } |
|
| 1836 | + |
|
| 1837 | + /** |
|
| 1838 | + * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
| 1839 | + * |
|
| 1840 | + * @since 1.9 |
|
| 1841 | + * |
|
| 1842 | + * @param $has_conditional_logic |
|
| 1843 | + * @param $form |
|
| 1844 | + * @return mixed|void |
|
| 1845 | + */ |
|
| 1846 | + public function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
| 1847 | + |
|
| 1848 | + if( ! $this->is_edit_entry() ) { |
|
| 1849 | + return $has_conditional_logic; |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */ |
|
| 1853 | + return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
| 1854 | + } |
|
| 1855 | + |
|
| 1856 | + |
|
| 1857 | + // --- User checks and nonces |
|
| 1858 | + |
|
| 1859 | + /** |
|
| 1860 | + * Check if the user can edit the entry |
|
| 1861 | + * |
|
| 1862 | + * - Is the nonce valid? |
|
| 1863 | + * - Does the user have the right caps for the entry |
|
| 1864 | + * - Is the entry in the trash? |
|
| 1865 | + * |
|
| 1866 | + * @todo Move to GVCommon |
|
| 1867 | + * |
|
| 1868 | + * @param boolean $echo Show error messages in the form? |
|
| 1869 | + * @return boolean True: can edit form. False: nope. |
|
| 1870 | + */ |
|
| 1871 | + private function user_can_edit_entry( $echo = false ) { |
|
| 1872 | + |
|
| 1873 | + $error = NULL; |
|
| 1874 | + |
|
| 1875 | + /** |
|
| 1876 | + * 1. Permalinks are turned off |
|
| 1877 | + * 2. There are two entries embedded using oEmbed |
|
| 1878 | + * 3. One of the entries has just been saved |
|
| 1879 | + */ |
|
| 1880 | + if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1881 | + |
|
| 1882 | + $error = true; |
|
| 1883 | + |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1887 | + |
|
| 1888 | + $error = true; |
|
| 1889 | + |
|
| 1890 | + } elseif( ! $this->verify_nonce() ) { |
|
| 1891 | + |
|
| 1892 | + /** |
|
| 1893 | + * If the Entry is embedded, there may be two entries on the same page. |
|
| 1894 | + * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
| 1895 | + */ |
|
| 1896 | + if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1897 | + $error = true; |
|
| 1898 | + } else { |
|
| 1899 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1900 | + } |
|
| 1901 | + |
|
| 1902 | + } |
|
| 1903 | + |
|
| 1904 | + if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1905 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1906 | + } |
|
| 1907 | + |
|
| 1908 | + if( $this->entry['status'] === 'trash' ) { |
|
| 1909 | + $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1910 | + } |
|
| 1911 | + |
|
| 1912 | + // No errors; everything's fine here! |
|
| 1913 | + if( empty( $error ) ) { |
|
| 1914 | + return true; |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + if( $echo && $error !== true ) { |
|
| 1918 | + |
|
| 1919 | + $error = esc_html( $error ); |
|
| 1920 | + |
|
| 1921 | + /** |
|
| 1922 | + * @since 1.9 |
|
| 1923 | + */ |
|
| 1924 | + if ( ! empty( $this->entry ) ) { |
|
| 1925 | + $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;" ) ); |
|
| 1926 | + } |
|
| 1982 | 1927 | |
| 1983 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1928 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1929 | + } |
|
| 1984 | 1930 | |
| 1985 | - // If the field has custom editing capaibilities set, check those |
|
| 1986 | - if( $field_cap ) { |
|
| 1987 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1988 | - } |
|
| 1989 | - |
|
| 1990 | - return false; |
|
| 1991 | - } |
|
| 1931 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1992 | 1932 | |
| 1933 | + return false; |
|
| 1934 | + } |
|
| 1935 | + |
|
| 1936 | + |
|
| 1937 | + /** |
|
| 1938 | + * Check whether a field is editable by the current user, and optionally display an error message |
|
| 1939 | + * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
| 1940 | + * @param array $field Field or field settings array |
|
| 1941 | + * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
| 1942 | + * @return boolean True: user can edit the current field; False: nope, they can't. |
|
| 1943 | + */ |
|
| 1944 | + private function user_can_edit_field( $field, $echo = false ) { |
|
| 1945 | + |
|
| 1946 | + $error = NULL; |
|
| 1947 | + |
|
| 1948 | + if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1949 | + $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + // No errors; everything's fine here! |
|
| 1953 | + if( empty( $error ) ) { |
|
| 1954 | + return true; |
|
| 1955 | + } |
|
| 1956 | + |
|
| 1957 | + if( $echo ) { |
|
| 1958 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1962 | + |
|
| 1963 | + return false; |
|
| 1964 | + |
|
| 1965 | + } |
|
| 1966 | + |
|
| 1967 | + |
|
| 1968 | + /** |
|
| 1969 | + * checks if user has permissions to edit a specific field |
|
| 1970 | + * |
|
| 1971 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
| 1972 | + * |
|
| 1973 | + * @param [type] $field [description] |
|
| 1974 | + * @return bool |
|
| 1975 | + */ |
|
| 1976 | + private function check_user_cap_edit_field( $field ) { |
|
| 1993 | 1977 | |
| 1994 | - /** |
|
| 1995 | - * Is the current nonce valid for editing the entry? |
|
| 1996 | - * @return boolean |
|
| 1997 | - */ |
|
| 1998 | - public function verify_nonce() { |
|
| 1978 | + // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
| 1979 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1980 | + return true; |
|
| 1981 | + } |
|
| 1999 | 1982 | |
| 2000 | - // Verify form submitted for editing single |
|
| 2001 | - if( $this->is_edit_entry_submission() ) { |
|
| 2002 | - $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
| 2003 | - } |
|
| 1983 | + $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 2004 | 1984 | |
| 2005 | - // Verify |
|
| 2006 | - else if( ! $this->is_edit_entry() ) { |
|
| 2007 | - $valid = false; |
|
| 2008 | - } |
|
| 1985 | + // If the field has custom editing capaibilities set, check those |
|
| 1986 | + if( $field_cap ) { |
|
| 1987 | + return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1988 | + } |
|
| 2009 | 1989 | |
| 2010 | - else { |
|
| 2011 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 2012 | - } |
|
| 1990 | + return false; |
|
| 1991 | + } |
|
| 2013 | 1992 | |
| 2014 | - /** |
|
| 2015 | - * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
| 2016 | - * @since 1.13 |
|
| 2017 | - * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
| 2018 | - * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
| 2019 | - */ |
|
| 2020 | - $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
| 2021 | 1993 | |
| 2022 | - return $valid; |
|
| 2023 | - } |
|
| 1994 | + /** |
|
| 1995 | + * Is the current nonce valid for editing the entry? |
|
| 1996 | + * @return boolean |
|
| 1997 | + */ |
|
| 1998 | + public function verify_nonce() { |
|
| 1999 | + |
|
| 2000 | + // Verify form submitted for editing single |
|
| 2001 | + if( $this->is_edit_entry_submission() ) { |
|
| 2002 | + $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
| 2003 | + } |
|
| 2004 | + |
|
| 2005 | + // Verify |
|
| 2006 | + else if( ! $this->is_edit_entry() ) { |
|
| 2007 | + $valid = false; |
|
| 2008 | + } |
|
| 2009 | + |
|
| 2010 | + else { |
|
| 2011 | + $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + /** |
|
| 2015 | + * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
| 2016 | + * @since 1.13 |
|
| 2017 | + * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
| 2018 | + * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
| 2019 | + */ |
|
| 2020 | + $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
| 2021 | + |
|
| 2022 | + return $valid; |
|
| 2023 | + } |
|
| 2024 | 2024 | |
| 2025 | 2025 | |
| 2026 | 2026 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @return GV_License_Handler |
| 41 | 41 | */ |
| 42 | 42 | public static function get_instance( GravityView_Settings $GFAddOn ) { |
| 43 | - if( empty( self::$instance ) ) { |
|
| 43 | + if ( empty( self::$instance ) ) { |
|
| 44 | 44 | self::$instance = new self( $GFAddOn ); |
| 45 | 45 | } |
| 46 | 46 | return self::$instance; |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | public function refresh_license_status() { |
| 71 | 71 | |
| 72 | 72 | // Only perform on GravityView pages |
| 73 | - if( ! gravityview_is_admin_page() ) { |
|
| 73 | + if ( ! gravityview_is_admin_page() ) { |
|
| 74 | 74 | return; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // The transient is fresh; don't fetch. |
| 78 | - if( $status = get_transient( self::status_transient_key ) ) { |
|
| 78 | + if ( $status = get_transient( self::status_transient_key ) ) { |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -101,37 +101,37 @@ discard block |
||
| 101 | 101 | $status = trim( $this->Addon->get_app_setting( 'license_key_status' ) ); |
| 102 | 102 | $key = trim( $this->Addon->get_app_setting( 'license_key' ) ); |
| 103 | 103 | |
| 104 | - if( !empty( $key ) ) { |
|
| 104 | + if ( ! empty( $key ) ) { |
|
| 105 | 105 | $response = $this->Addon->get_app_setting( 'license_key_response' ); |
| 106 | - $response = is_array( $response ) ? (object) $response : json_decode( $response ); |
|
| 106 | + $response = is_array( $response ) ? (object)$response : json_decode( $response ); |
|
| 107 | 107 | } else { |
| 108 | 108 | $response = array(); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | wp_localize_script( 'gv-admin-edd-license', 'GVGlobals', array( |
| 112 | 112 | 'license_box' => $this->get_license_message( $response ) |
| 113 | - )); |
|
| 113 | + ) ); |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | $fields = array( |
| 117 | 117 | array( |
| 118 | 118 | 'name' => 'edd-activate', |
| 119 | - 'value' => __('Activate License', 'gravityview'), |
|
| 120 | - 'data-pending_text' => __('Verifying license…', 'gravityview'), |
|
| 119 | + 'value' => __( 'Activate License', 'gravityview' ), |
|
| 120 | + 'data-pending_text' => __( 'Verifying license…', 'gravityview' ), |
|
| 121 | 121 | 'data-edd_action' => 'activate_license', |
| 122 | 122 | 'class' => 'button-primary', |
| 123 | 123 | ), |
| 124 | 124 | array( |
| 125 | 125 | 'name' => 'edd-deactivate', |
| 126 | - 'value' => __('Deactivate License', 'gravityview'), |
|
| 127 | - 'data-pending_text' => __('Deactivating license…', 'gravityview'), |
|
| 126 | + 'value' => __( 'Deactivate License', 'gravityview' ), |
|
| 127 | + 'data-pending_text' => __( 'Deactivating license…', 'gravityview' ), |
|
| 128 | 128 | 'data-edd_action' => 'deactivate_license', |
| 129 | 129 | 'class' => ( empty( $status ) ? 'button-primary hide' : 'button-primary' ), |
| 130 | 130 | ), |
| 131 | 131 | array( |
| 132 | 132 | 'name' => 'edd-check', |
| 133 | - 'value' => __('Check License', 'gravityview'), |
|
| 134 | - 'data-pending_text' => __('Verifying license…', 'gravityview'), |
|
| 133 | + 'value' => __( 'Check License', 'gravityview' ), |
|
| 134 | + 'data-pending_text' => __( 'Verifying license…', 'gravityview' ), |
|
| 135 | 135 | 'title' => 'Check the license before saving it', |
| 136 | 136 | 'data-edd_action' => 'check_license', |
| 137 | 137 | 'class' => 'button-secondary', |
@@ -141,17 +141,17 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | $class = 'button gv-edd-action'; |
| 143 | 143 | |
| 144 | - $class .= ( !empty( $key ) && $status !== 'valid' ) ? '' : ' hide'; |
|
| 144 | + $class .= ( ! empty( $key ) && $status !== 'valid' ) ? '' : ' hide'; |
|
| 145 | 145 | |
| 146 | 146 | $disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled'; |
| 147 | 147 | |
| 148 | 148 | $submit = '<div class="gv-edd-button-wrapper">'; |
| 149 | 149 | foreach ( $fields as $field ) { |
| 150 | - $field['type'] = 'button'; |
|
| 151 | - $field['class'] = isset( $field['class'] ) ? $field['class'] . ' '. $class : $class; |
|
| 152 | - $field['style'] = 'margin-left: 10px;'; |
|
| 153 | - if( $disabled_attribute ) { |
|
| 154 | - $field['disabled'] = $disabled_attribute; |
|
| 150 | + $field[ 'type' ] = 'button'; |
|
| 151 | + $field[ 'class' ] = isset( $field[ 'class' ] ) ? $field[ 'class' ] . ' ' . $class : $class; |
|
| 152 | + $field[ 'style' ] = 'margin-left: 10px;'; |
|
| 153 | + if ( $disabled_attribute ) { |
|
| 154 | + $field[ 'disabled' ] = $disabled_attribute; |
|
| 155 | 155 | } |
| 156 | 156 | $submit .= $this->Addon->settings_submit( $field, $echo ); |
| 157 | 157 | } |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | private function setup_edd() { |
| 169 | 169 | |
| 170 | - if( !class_exists('EDD_SL_Plugin_Updater') ) { |
|
| 171 | - require_once( GRAVITYVIEW_DIR . 'includes/lib/EDD_SL_Plugin_Updater.php'); |
|
| 170 | + if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
|
| 171 | + require_once( GRAVITYVIEW_DIR . 'includes/lib/EDD_SL_Plugin_Updater.php' ); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // setup the updater |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | 'url' => home_url(), |
| 206 | 206 | ); |
| 207 | 207 | |
| 208 | - if( !empty( $action ) ) { |
|
| 209 | - $settings['edd_action'] = esc_attr( $action ); |
|
| 208 | + if ( ! empty( $action ) ) { |
|
| 209 | + $settings[ 'edd_action' ] = esc_attr( $action ); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $settings = array_map( 'urlencode', $settings ); |
@@ -220,14 +220,14 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | private function _license_get_remote_response( $data, $license = '' ) { |
| 222 | 222 | |
| 223 | - $api_params = $this->_get_edd_settings( $data['edd_action'], $license ); |
|
| 223 | + $api_params = $this->_get_edd_settings( $data[ 'edd_action' ], $license ); |
|
| 224 | 224 | |
| 225 | 225 | $url = add_query_arg( $api_params, self::url ); |
| 226 | 226 | |
| 227 | 227 | $response = wp_remote_get( $url, array( |
| 228 | 228 | 'timeout' => 15, |
| 229 | 229 | 'sslverify' => false, |
| 230 | - )); |
|
| 230 | + ) ); |
|
| 231 | 231 | |
| 232 | 232 | if ( is_wp_error( $response ) ) { |
| 233 | 233 | return array(); |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | function get_license_message( $license_data ) { |
| 262 | 262 | |
| 263 | - if( empty( $license_data ) ) { |
|
| 263 | + if ( empty( $license_data ) ) { |
|
| 264 | 264 | $message = ''; |
| 265 | 265 | } else { |
| 266 | 266 | |
| 267 | - if( ! empty( $license_data->error ) ) { |
|
| 267 | + if ( ! empty( $license_data->error ) ) { |
|
| 268 | 268 | $class = 'error'; |
| 269 | 269 | $string_key = $license_data->error; |
| 270 | 270 | } else { |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | $string_key = $license_data->license; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $message = sprintf( '<p><strong>%s: %s</strong></p>', $this->strings('status'), $this->strings( $string_key, $license_data ) ); |
|
| 275 | + $message = sprintf( '<p><strong>%s: %s</strong></p>', $this->strings( 'status' ), $this->strings( $string_key, $license_data ) ); |
|
| 276 | 276 | |
| 277 | 277 | $message = $this->generate_license_box( $message, $class ); |
| 278 | 278 | } |
@@ -309,18 +309,18 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | public function license_details( $response = array() ) { |
| 311 | 311 | |
| 312 | - $response = (array) $response; |
|
| 312 | + $response = (array)$response; |
|
| 313 | 313 | |
| 314 | 314 | $return = ''; |
| 315 | 315 | $wrapper = '<span class="gv-license-details" aria-live="polite" aria-busy="false">%s</span>'; |
| 316 | 316 | |
| 317 | - if( ! empty( $response['license_key'] ) ) { |
|
| 317 | + if ( ! empty( $response[ 'license_key' ] ) ) { |
|
| 318 | 318 | |
| 319 | 319 | $return .= '<h3>' . esc_html__( 'License Details:', 'gravityview' ) . '</h3>'; |
| 320 | 320 | |
| 321 | 321 | if ( in_array( rgar( $response, 'license' ), array( 'invalid', 'deactivated' ) ) ) { |
| 322 | - $return .= $this->strings( $response['license'], $response ); |
|
| 323 | - } elseif ( ! empty( $response['license_name'] ) ) { |
|
| 322 | + $return .= $this->strings( $response[ 'license' ], $response ); |
|
| 323 | + } elseif ( ! empty( $response[ 'license_name' ] ) ) { |
|
| 324 | 324 | |
| 325 | 325 | $response_keys = array( |
| 326 | 326 | 'license_name' => '', |
@@ -335,19 +335,19 @@ discard block |
||
| 335 | 335 | // Make sure all the keys are set |
| 336 | 336 | $response = wp_parse_args( $response, $response_keys ); |
| 337 | 337 | |
| 338 | - $login_link = sprintf( '<a href="%s" class="howto" rel="external">%s</a>', esc_url( sprintf( 'https://gravityview.co/wp-login.php?username=%s', $response['customer_email'] ) ), esc_html__( 'Access your GravityView account', 'gravityview' ) ); |
|
| 339 | - $local_text = ( ! empty( $response['is_local'] ) ? '<span class="howto">' . __( 'This development site does not count toward license activation limits', 'gravityview' ) . '</span>' : '' ); |
|
| 338 | + $login_link = sprintf( '<a href="%s" class="howto" rel="external">%s</a>', esc_url( sprintf( 'https://gravityview.co/wp-login.php?username=%s', $response[ 'customer_email' ] ) ), esc_html__( 'Access your GravityView account', 'gravityview' ) ); |
|
| 339 | + $local_text = ( ! empty( $response[ 'is_local' ] ) ? '<span class="howto">' . __( 'This development site does not count toward license activation limits', 'gravityview' ) . '</span>' : '' ); |
|
| 340 | 340 | $details = array( |
| 341 | - 'license' => sprintf( esc_html__( 'License level: %s', 'gravityview' ), esc_html( $response['license_name'] ), esc_html( $response['license_limit'] ) ), |
|
| 342 | - 'licensed_to' => sprintf( esc_html_x( 'Licensed to: %1$s (%2$s)', '1: Customer name; 2: Customer email', 'gravityview' ), esc_html__( $response['customer_name'], 'gravityview' ), esc_html__( $response['customer_email'], 'gravityview' ) ) . $login_link, |
|
| 343 | - 'activations' => sprintf( esc_html__( 'Activations: %d of %s sites', 'gravityview' ), intval( $response['site_count'] ), esc_html( $response['license_limit'] ) ) . $local_text, |
|
| 344 | - 'expires' => sprintf( esc_html__( 'Renew on: %s', 'gravityview' ), date_i18n( get_option( 'date_format' ), strtotime( $response['expires'] ) - DAY_IN_SECONDS ) ), |
|
| 345 | - 'upgrade' => $this->get_upgrade_html( $response['upgrades'] ), |
|
| 341 | + 'license' => sprintf( esc_html__( 'License level: %s', 'gravityview' ), esc_html( $response[ 'license_name' ] ), esc_html( $response[ 'license_limit' ] ) ), |
|
| 342 | + 'licensed_to' => sprintf( esc_html_x( 'Licensed to: %1$s (%2$s)', '1: Customer name; 2: Customer email', 'gravityview' ), esc_html__( $response[ 'customer_name' ], 'gravityview' ), esc_html__( $response[ 'customer_email' ], 'gravityview' ) ) . $login_link, |
|
| 343 | + 'activations' => sprintf( esc_html__( 'Activations: %d of %s sites', 'gravityview' ), intval( $response[ 'site_count' ] ), esc_html( $response[ 'license_limit' ] ) ) . $local_text, |
|
| 344 | + 'expires' => sprintf( esc_html__( 'Renew on: %s', 'gravityview' ), date_i18n( get_option( 'date_format' ), strtotime( $response[ 'expires' ] ) - DAY_IN_SECONDS ) ), |
|
| 345 | + 'upgrade' => $this->get_upgrade_html( $response[ 'upgrades' ] ), |
|
| 346 | 346 | ); |
| 347 | 347 | |
| 348 | - if ( ! empty( $response['error'] ) && 'expired' === $response['error'] ) { |
|
| 349 | - unset( $details['upgrade'] ); |
|
| 350 | - $details['expires'] = '<div class="error inline"><p>' . $this->strings( 'expired', $response ) . '</p></div>'; |
|
| 348 | + if ( ! empty( $response[ 'error' ] ) && 'expired' === $response[ 'error' ] ) { |
|
| 349 | + unset( $details[ 'upgrade' ] ); |
|
| 350 | + $details[ 'expires' ] = '<div class="error inline"><p>' . $this->strings( 'expired', $response ) . '</p></div>'; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | $return .= '<ul><li>' . implode( '</li><li>', array_filter( $details ) ) . '</li></ul>'; |
@@ -370,11 +370,11 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | $output = ''; |
| 372 | 372 | |
| 373 | - if( ! empty( $upgrades ) ) { |
|
| 373 | + if ( ! empty( $upgrades ) ) { |
|
| 374 | 374 | |
| 375 | 375 | $locale_parts = explode( '_', get_locale() ); |
| 376 | 376 | |
| 377 | - $is_english = ( 'en' === $locale_parts[0] ); |
|
| 377 | + $is_english = ( 'en' === $locale_parts[ 0 ] ); |
|
| 378 | 378 | |
| 379 | 379 | $output .= '<h4>' . esc_html__( 'Upgrades available:', 'gravityview' ) . '</h4>'; |
| 380 | 380 | |
@@ -382,14 +382,14 @@ discard block |
||
| 382 | 382 | |
| 383 | 383 | foreach ( $upgrades as $upgrade_id => $upgrade ) { |
| 384 | 384 | |
| 385 | - $upgrade = (object) $upgrade; |
|
| 385 | + $upgrade = (object)$upgrade; |
|
| 386 | 386 | |
| 387 | 387 | $anchor_text = sprintf( esc_html_x( 'Upgrade to %1$s for %2$s', '1: GravityView upgrade name, 2: Cost of upgrade', 'gravityview' ), esc_attr( $upgrade->name ), esc_attr( $upgrade->price ) ); |
| 388 | 388 | |
| 389 | - if( $is_english && isset( $upgrade->description ) ) { |
|
| 389 | + if ( $is_english && isset( $upgrade->description ) ) { |
|
| 390 | 390 | $message = esc_html( $upgrade->description ); |
| 391 | 391 | } else { |
| 392 | - switch( $upgrade->price_id ) { |
|
| 392 | + switch ( $upgrade->price_id ) { |
|
| 393 | 393 | // Interstellar |
| 394 | 394 | case 1: |
| 395 | 395 | default: |
@@ -427,16 +427,16 @@ discard block |
||
| 427 | 427 | */ |
| 428 | 428 | public function license_call( $array = array() ) { |
| 429 | 429 | |
| 430 | - $is_ajax = ( defined('DOING_AJAX') && DOING_AJAX ); |
|
| 431 | - $data = empty( $array ) ? $_POST['data'] : $array; |
|
| 430 | + $is_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
| 431 | + $data = empty( $array ) ? $_POST[ 'data' ] : $array; |
|
| 432 | 432 | $has_cap = GVCommon::has_cap( 'gravityview_edit_settings' ); |
| 433 | 433 | |
| 434 | - if ( $is_ajax && empty( $data['license'] ) ) { |
|
| 435 | - die( - 1 ); |
|
| 434 | + if ( $is_ajax && empty( $data[ 'license' ] ) ) { |
|
| 435 | + die( -1 ); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | // If the user isn't allowed to edit settings, show an error message |
| 439 | - if( ! $has_cap ) { |
|
| 439 | + if ( ! $has_cap ) { |
|
| 440 | 440 | $license_data = new stdClass(); |
| 441 | 441 | $license_data->error = 'capability'; |
| 442 | 442 | $license_data->message = $this->get_license_message( $license_data ); |
@@ -460,9 +460,9 @@ discard block |
||
| 460 | 460 | |
| 461 | 461 | $json = json_encode( $license_data ); |
| 462 | 462 | |
| 463 | - $update_license = ( ! isset( $data['update'] ) || ! empty( $data['update'] ) ); |
|
| 463 | + $update_license = ( ! isset( $data[ 'update' ] ) || ! empty( $data[ 'update' ] ) ); |
|
| 464 | 464 | |
| 465 | - $is_check_action_button = ( 'check_license' === $data['edd_action'] && defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
| 465 | + $is_check_action_button = ( 'check_license' === $data[ 'edd_action' ] && defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
| 466 | 466 | |
| 467 | 467 | // Failed is the response from trying to de-activate a license and it didn't work. |
| 468 | 468 | // This likely happened because people entered in a different key and clicked "Deactivate", |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | // most likely a mistake. |
| 471 | 471 | if ( $license_data->license !== 'failed' && ! $is_check_action_button && $update_license ) { |
| 472 | 472 | |
| 473 | - if ( ! empty( $data['field_id'] ) ) { |
|
| 473 | + if ( ! empty( $data[ 'field_id' ] ) ) { |
|
| 474 | 474 | set_transient( self::status_transient_key, $license_data, DAY_IN_SECONDS ); |
| 475 | 475 | } |
| 476 | 476 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | if ( $is_ajax ) { |
| 482 | 482 | exit( $json ); |
| 483 | 483 | } else { // Non-ajax call |
| 484 | - return ( rgget('format', $data ) === 'object' ) ? $license_data : $json; |
|
| 484 | + return ( rgget( 'format', $data ) === 'object' ) ? $license_data : $json; |
|
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
@@ -495,9 +495,9 @@ discard block |
||
| 495 | 495 | // Update option with passed data license |
| 496 | 496 | $settings = $this->Addon->get_app_settings(); |
| 497 | 497 | |
| 498 | - $settings['license_key'] = $license_data->license_key = trim( $data['license'] ); |
|
| 499 | - $settings['license_key_status'] = $license_data->license; |
|
| 500 | - $settings['license_key_response'] = (array)$license_data; |
|
| 498 | + $settings[ 'license_key' ] = $license_data->license_key = trim( $data[ 'license' ] ); |
|
| 499 | + $settings[ 'license_key_status' ] = $license_data->license; |
|
| 500 | + $settings[ 'license_key_response' ] = (array)$license_data; |
|
| 501 | 501 | |
| 502 | 502 | $this->Addon->update_app_settings( $settings ); |
| 503 | 503 | } |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | */ |
| 511 | 511 | private function get_license_renewal_url( $license_data ) { |
| 512 | 512 | $license_data = is_array( $license_data ) ? (object)$license_data : $license_data; |
| 513 | - $renew_license_url = ( ! empty( $license_data ) && !empty( $license_data->license_key ) ) ? sprintf( 'https://gravityview.co/checkout/?download_id=17&edd_license_key=%s&utm_source=admin_notice&utm_medium=admin&utm_content=expired&utm_campaign=Activation&force_login=1', $license_data->license_key ) : 'https://gravityview.co/account/'; |
|
| 513 | + $renew_license_url = ( ! empty( $license_data ) && ! empty( $license_data->license_key ) ) ? sprintf( 'https://gravityview.co/checkout/?download_id=17&edd_license_key=%s&utm_source=admin_notice&utm_medium=admin&utm_content=expired&utm_campaign=Activation&force_login=1', $license_data->license_key ) : 'https://gravityview.co/account/'; |
|
| 514 | 514 | return $renew_license_url; |
| 515 | 515 | } |
| 516 | 516 | |
@@ -525,31 +525,31 @@ discard block |
||
| 525 | 525 | |
| 526 | 526 | |
| 527 | 527 | $strings = array( |
| 528 | - 'status' => esc_html__('Status', 'gravityview'), |
|
| 529 | - 'error' => esc_html__('There was an error processing the request.', 'gravityview'), |
|
| 530 | - 'failed' => esc_html__('Could not deactivate the license. The license key you attempted to deactivate may not be active or valid.', 'gravityview'), |
|
| 531 | - 'site_inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'), |
|
| 532 | - 'inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'), |
|
| 533 | - 'no_activations_left' => esc_html__('Invalid: this license has reached its activation limit.', 'gravityview') . ' ' . sprintf( esc_html__('You can manage license activations %son your GravityView account page%s.', 'gravityview'), '<a href="https://gravityview.co/account/#licenses">', '</a>' ), |
|
| 534 | - 'deactivated' => esc_html__('The license has been deactivated.', 'gravityview'), |
|
| 535 | - 'valid' => esc_html__('The license key is valid and active.', 'gravityview'), |
|
| 536 | - 'invalid' => esc_html__('The license key entered is invalid.', 'gravityview'), |
|
| 537 | - 'missing' => esc_html__('Invalid license key.', 'gravityview'), |
|
| 538 | - 'revoked' => esc_html__('This license key has been revoked.', 'gravityview'), |
|
| 539 | - 'expired' => sprintf( esc_html__('This license key has expired. %sRenew your license on the GravityView website%s to receive updates and support.', 'gravityview'), '<a href="'. esc_url( $this->get_license_renewal_url( $license_data ) ) .'">', '</a>' ), |
|
| 528 | + 'status' => esc_html__( 'Status', 'gravityview' ), |
|
| 529 | + 'error' => esc_html__( 'There was an error processing the request.', 'gravityview' ), |
|
| 530 | + 'failed' => esc_html__( 'Could not deactivate the license. The license key you attempted to deactivate may not be active or valid.', 'gravityview' ), |
|
| 531 | + 'site_inactive' => esc_html__( 'The license key is valid, but it has not been activated for this site.', 'gravityview' ), |
|
| 532 | + 'inactive' => esc_html__( 'The license key is valid, but it has not been activated for this site.', 'gravityview' ), |
|
| 533 | + 'no_activations_left' => esc_html__( 'Invalid: this license has reached its activation limit.', 'gravityview' ) . ' ' . sprintf( esc_html__( 'You can manage license activations %son your GravityView account page%s.', 'gravityview' ), '<a href="https://gravityview.co/account/#licenses">', '</a>' ), |
|
| 534 | + 'deactivated' => esc_html__( 'The license has been deactivated.', 'gravityview' ), |
|
| 535 | + 'valid' => esc_html__( 'The license key is valid and active.', 'gravityview' ), |
|
| 536 | + 'invalid' => esc_html__( 'The license key entered is invalid.', 'gravityview' ), |
|
| 537 | + 'missing' => esc_html__( 'Invalid license key.', 'gravityview' ), |
|
| 538 | + 'revoked' => esc_html__( 'This license key has been revoked.', 'gravityview' ), |
|
| 539 | + 'expired' => sprintf( esc_html__( 'This license key has expired. %sRenew your license on the GravityView website%s to receive updates and support.', 'gravityview' ), '<a href="' . esc_url( $this->get_license_renewal_url( $license_data ) ) . '">', '</a>' ), |
|
| 540 | 540 | 'capability' => esc_html__( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ), |
| 541 | 541 | |
| 542 | - 'verifying_license' => esc_html__('Verifying license…', 'gravityview'), |
|
| 543 | - 'activate_license' => esc_html__('Activate License', 'gravityview'), |
|
| 544 | - 'deactivate_license' => esc_html__('Deactivate License', 'gravityview'), |
|
| 545 | - 'check_license' => esc_html__('Verify License', 'gravityview'), |
|
| 542 | + 'verifying_license' => esc_html__( 'Verifying license…', 'gravityview' ), |
|
| 543 | + 'activate_license' => esc_html__( 'Activate License', 'gravityview' ), |
|
| 544 | + 'deactivate_license' => esc_html__( 'Deactivate License', 'gravityview' ), |
|
| 545 | + 'check_license' => esc_html__( 'Verify License', 'gravityview' ), |
|
| 546 | 546 | ); |
| 547 | 547 | |
| 548 | - if( empty( $status ) ) { |
|
| 548 | + if ( empty( $status ) ) { |
|
| 549 | 549 | return $strings; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - if( isset( $strings[ $status ] ) ) { |
|
| 552 | + if ( isset( $strings[ $status ] ) ) { |
|
| 553 | 553 | return $strings[ $status ]; |
| 554 | 554 | } |
| 555 | 555 | |