@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | // Display the success message |
| 537 | 537 | if( rgpost('action') === 'update' ) { |
| 538 | 538 | |
| 539 | - if( ! $this->is_valid ){ |
|
| 539 | + if( ! $this->is_valid ) { |
|
| 540 | 540 | |
| 541 | 541 | // Keeping this compatible with Gravity Forms. |
| 542 | 542 | $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
@@ -1519,9 +1519,7 @@ discard block |
||
| 1519 | 1519 | // Verify |
| 1520 | 1520 | else if( ! $this->is_edit_entry() ) { |
| 1521 | 1521 | $valid = false; |
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - else { |
|
| 1522 | + } else { |
|
| 1525 | 1523 | $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
| 1526 | 1524 | } |
| 1527 | 1525 | |
@@ -1,27 +1,27 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * GravityView Edit Entry - render frontend |
|
| 4 | - * |
|
| 5 | - * @package GravityView |
|
| 6 | - * @license GPL2+ |
|
| 7 | - * @author Katz Web Services, Inc. |
|
| 8 | - * @link http://gravityview.co |
|
| 9 | - * @copyright Copyright 2014, Katz Web Services, Inc. |
|
| 10 | - */ |
|
| 3 | + * GravityView Edit Entry - render frontend |
|
| 4 | + * |
|
| 5 | + * @package GravityView |
|
| 6 | + * @license GPL2+ |
|
| 7 | + * @author Katz Web Services, Inc. |
|
| 8 | + * @link http://gravityview.co |
|
| 9 | + * @copyright Copyright 2014, Katz Web Services, Inc. |
|
| 10 | + */ |
|
| 11 | 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 | - protected $loader; |
|
| 19 | + protected $loader; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * @var string String used to generate unique nonce for the entry/form/view combination. Allows access to edit page. |
| 23 | 23 | */ |
| 24 | - static $nonce_key; |
|
| 24 | + static $nonce_key; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * @since 1.9 |
@@ -41,124 +41,124 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | private static $supports_product_fields = false; |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Gravity Forms entry array |
|
| 46 | - * |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - var $entry; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Gravity Forms form array |
|
| 53 | - * |
|
| 54 | - * @var array |
|
| 55 | - */ |
|
| 56 | - var $form; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Gravity Forms form array after the form validation process |
|
| 60 | - * @since 1.13 |
|
| 61 | - * @var array |
|
| 62 | - */ |
|
| 63 | - var $form_after_validation = null; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gravity Forms form id |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - var $form_id; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * ID of the current view |
|
| 74 | - * |
|
| 75 | - * @var int |
|
| 76 | - */ |
|
| 77 | - var $view_id; |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Updated entry is valid (GF Validation object) |
|
| 82 | - * |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 85 | - var $is_valid = NULL; |
|
| 86 | - |
|
| 87 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
| 88 | - $this->loader = $loader; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - function load() { |
|
| 92 | - |
|
| 93 | - /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
| 94 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 95 | - |
|
| 96 | - // Don't display an embedded form when editing an entry |
|
| 97 | - add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
|
| 98 | - add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
|
| 99 | - |
|
| 100 | - // Stop Gravity Forms processing what is ours! |
|
| 101 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 102 | - |
|
| 103 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 104 | - |
|
| 105 | - add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
| 106 | - |
|
| 107 | - // Disable conditional logic if needed (since 1.9) |
|
| 108 | - add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
| 109 | - |
|
| 110 | - // Make sure GF doesn't validate max files (since 1.9) |
|
| 111 | - add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
| 112 | - |
|
| 113 | - // Add fields expected by GFFormDisplay::validate() |
|
| 114 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 115 | - |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Don't show any forms embedded on a page when GravityView is in Edit Entry mode |
|
| 120 | - * |
|
| 121 | - * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action |
|
| 122 | - * And then removes it on the `wp_footer` action |
|
| 123 | - * |
|
| 124 | - * @since 1.16.1 |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - function prevent_render_form() { |
|
| 129 | - if( $this->is_edit_entry() ) { |
|
| 130 | - if( 'wp_head' === current_filter() ) { |
|
| 131 | - add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 132 | - } else { |
|
| 133 | - remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
| 140 | - * backend form, we need to prevent them from saving twice. |
|
| 141 | - * @return void |
|
| 142 | - */ |
|
| 143 | - function prevent_maybe_process_form() { |
|
| 144 | - |
|
| 145 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 146 | - |
|
| 147 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 148 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Is the current page an Edit Entry page? |
|
| 154 | - * @return boolean |
|
| 155 | - */ |
|
| 156 | - public function is_edit_entry() { |
|
| 157 | - |
|
| 158 | - $gf_page = ( 'entry' === RGForms::get( 'view' ) ); |
|
| 159 | - |
|
| 160 | - return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); |
|
| 161 | - } |
|
| 44 | + /** |
|
| 45 | + * Gravity Forms entry array |
|
| 46 | + * |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + var $entry; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Gravity Forms form array |
|
| 53 | + * |
|
| 54 | + * @var array |
|
| 55 | + */ |
|
| 56 | + var $form; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Gravity Forms form array after the form validation process |
|
| 60 | + * @since 1.13 |
|
| 61 | + * @var array |
|
| 62 | + */ |
|
| 63 | + var $form_after_validation = null; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gravity Forms form id |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + var $form_id; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * ID of the current view |
|
| 74 | + * |
|
| 75 | + * @var int |
|
| 76 | + */ |
|
| 77 | + var $view_id; |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Updated entry is valid (GF Validation object) |
|
| 82 | + * |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | + var $is_valid = NULL; |
|
| 86 | + |
|
| 87 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
| 88 | + $this->loader = $loader; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + function load() { |
|
| 92 | + |
|
| 93 | + /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
| 94 | + include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 95 | + |
|
| 96 | + // Don't display an embedded form when editing an entry |
|
| 97 | + add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
|
| 98 | + add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
|
| 99 | + |
|
| 100 | + // Stop Gravity Forms processing what is ours! |
|
| 101 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 102 | + |
|
| 103 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 104 | + |
|
| 105 | + add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
| 106 | + |
|
| 107 | + // Disable conditional logic if needed (since 1.9) |
|
| 108 | + add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
| 109 | + |
|
| 110 | + // Make sure GF doesn't validate max files (since 1.9) |
|
| 111 | + add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
| 112 | + |
|
| 113 | + // Add fields expected by GFFormDisplay::validate() |
|
| 114 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 115 | + |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Don't show any forms embedded on a page when GravityView is in Edit Entry mode |
|
| 120 | + * |
|
| 121 | + * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action |
|
| 122 | + * And then removes it on the `wp_footer` action |
|
| 123 | + * |
|
| 124 | + * @since 1.16.1 |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + function prevent_render_form() { |
|
| 129 | + if( $this->is_edit_entry() ) { |
|
| 130 | + if( 'wp_head' === current_filter() ) { |
|
| 131 | + add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 132 | + } else { |
|
| 133 | + remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
| 140 | + * backend form, we need to prevent them from saving twice. |
|
| 141 | + * @return void |
|
| 142 | + */ |
|
| 143 | + function prevent_maybe_process_form() { |
|
| 144 | + |
|
| 145 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 146 | + |
|
| 147 | + if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 148 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Is the current page an Edit Entry page? |
|
| 154 | + * @return boolean |
|
| 155 | + */ |
|
| 156 | + public function is_edit_entry() { |
|
| 157 | + |
|
| 158 | + $gf_page = ( 'entry' === RGForms::get( 'view' ) ); |
|
| 159 | + |
|
| 160 | + return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | 164 | * Is the current page an Edit Entry page? |
@@ -169,422 +169,422 @@ discard block |
||
| 169 | 169 | return !empty( $_POST[ self::$nonce_field ] ); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * When Edit entry view is requested setup the vars |
|
| 174 | - */ |
|
| 175 | - function setup_vars() { |
|
| 176 | - $gravityview_view = GravityView_View::getInstance(); |
|
| 172 | + /** |
|
| 173 | + * When Edit entry view is requested setup the vars |
|
| 174 | + */ |
|
| 175 | + function setup_vars() { |
|
| 176 | + $gravityview_view = GravityView_View::getInstance(); |
|
| 177 | 177 | |
| 178 | 178 | |
| 179 | - $entries = $gravityview_view->getEntries(); |
|
| 180 | - $this->entry = $entries[0]; |
|
| 179 | + $entries = $gravityview_view->getEntries(); |
|
| 180 | + $this->entry = $entries[0]; |
|
| 181 | 181 | |
| 182 | 182 | |
| 183 | - $this->form = $gravityview_view->getForm(); |
|
| 184 | - $this->form_id = $gravityview_view->getFormId(); |
|
| 185 | - $this->view_id = $gravityview_view->getViewId(); |
|
| 183 | + $this->form = $gravityview_view->getForm(); |
|
| 184 | + $this->form_id = $gravityview_view->getFormId(); |
|
| 185 | + $this->view_id = $gravityview_view->getViewId(); |
|
| 186 | 186 | |
| 187 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 188 | - } |
|
| 187 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * Load required files and trigger edit flow |
|
| 193 | - * |
|
| 194 | - * Run when the is_edit_entry returns true. |
|
| 195 | - * |
|
| 196 | - * @param GravityView_View_Data $gv_data GravityView Data object |
|
| 197 | - * @return void |
|
| 198 | - */ |
|
| 199 | - function init( $gv_data ) { |
|
| 191 | + /** |
|
| 192 | + * Load required files and trigger edit flow |
|
| 193 | + * |
|
| 194 | + * Run when the is_edit_entry returns true. |
|
| 195 | + * |
|
| 196 | + * @param GravityView_View_Data $gv_data GravityView Data object |
|
| 197 | + * @return void |
|
| 198 | + */ |
|
| 199 | + function init( $gv_data ) { |
|
| 200 | 200 | |
| 201 | - require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
| 202 | - require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
| 201 | + require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
| 202 | + require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
| 203 | 203 | |
| 204 | - $this->setup_vars(); |
|
| 204 | + $this->setup_vars(); |
|
| 205 | 205 | |
| 206 | - // Multiple Views embedded, don't proceed if nonce fails |
|
| 207 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 208 | - return; |
|
| 209 | - } |
|
| 206 | + // Multiple Views embedded, don't proceed if nonce fails |
|
| 207 | + if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 208 | + return; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - // Sorry, you're not allowed here. |
|
| 212 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
| 213 | - return; |
|
| 214 | - } |
|
| 211 | + // Sorry, you're not allowed here. |
|
| 212 | + if( false === $this->user_can_edit_entry( true ) ) { |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - $this->print_scripts(); |
|
| 216 | + $this->print_scripts(); |
|
| 217 | 217 | |
| 218 | - $this->process_save(); |
|
| 218 | + $this->process_save(); |
|
| 219 | 219 | |
| 220 | - $this->edit_entry_form(); |
|
| 220 | + $this->edit_entry_form(); |
|
| 221 | 221 | |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Force Gravity Forms to output scripts as if it were in the admin |
|
| 227 | - * @return void |
|
| 228 | - */ |
|
| 229 | - function print_scripts() { |
|
| 230 | - $gravityview_view = GravityView_View::getInstance(); |
|
| 225 | + /** |
|
| 226 | + * Force Gravity Forms to output scripts as if it were in the admin |
|
| 227 | + * @return void |
|
| 228 | + */ |
|
| 229 | + function print_scripts() { |
|
| 230 | + $gravityview_view = GravityView_View::getInstance(); |
|
| 231 | 231 | |
| 232 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 232 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 233 | 233 | |
| 234 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 234 | + GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 235 | 235 | |
| 236 | - // Sack is required for images |
|
| 237 | - wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
| 238 | - } |
|
| 236 | + // Sack is required for images |
|
| 237 | + wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Process edit entry form save |
|
| 243 | - */ |
|
| 244 | - function process_save() { |
|
| 241 | + /** |
|
| 242 | + * Process edit entry form save |
|
| 243 | + */ |
|
| 244 | + function process_save() { |
|
| 245 | 245 | |
| 246 | - if( empty( $_POST ) ) { |
|
| 247 | - return; |
|
| 248 | - } |
|
| 246 | + if( empty( $_POST ) ) { |
|
| 247 | + return; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - // Make sure the entry, view, and form IDs are all correct |
|
| 251 | - $valid = $this->verify_nonce(); |
|
| 250 | + // Make sure the entry, view, and form IDs are all correct |
|
| 251 | + $valid = $this->verify_nonce(); |
|
| 252 | 252 | |
| 253 | - if( !$valid ) { |
|
| 254 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 255 | - return; |
|
| 256 | - } |
|
| 253 | + if( !$valid ) { |
|
| 254 | + do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 255 | + return; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 259 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 260 | - return; |
|
| 261 | - } |
|
| 258 | + if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 259 | + do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 260 | + return; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 263 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 264 | 264 | |
| 265 | - $this->process_save_process_files( $this->form_id ); |
|
| 265 | + $this->process_save_process_files( $this->form_id ); |
|
| 266 | 266 | |
| 267 | - $this->validate(); |
|
| 267 | + $this->validate(); |
|
| 268 | 268 | |
| 269 | - if( $this->is_valid ) { |
|
| 269 | + if( $this->is_valid ) { |
|
| 270 | 270 | |
| 271 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
| 271 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * @hack This step is needed to unset the adminOnly from form fields |
|
| 275 | - */ |
|
| 276 | - $form = $this->form_prepare_for_save(); |
|
| 273 | + /** |
|
| 274 | + * @hack This step is needed to unset the adminOnly from form fields |
|
| 275 | + */ |
|
| 276 | + $form = $this->form_prepare_for_save(); |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
| 280 | - */ |
|
| 281 | - unset( $_GET['page'] ); |
|
| 278 | + /** |
|
| 279 | + * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
| 280 | + */ |
|
| 281 | + unset( $_GET['page'] ); |
|
| 282 | 282 | |
| 283 | - GFFormsModel::save_lead( $form, $this->entry ); |
|
| 283 | + GFFormsModel::save_lead( $form, $this->entry ); |
|
| 284 | 284 | |
| 285 | - // If there's a post associated with the entry, process post fields |
|
| 286 | - if( !empty( $this->entry['post_id'] ) ) { |
|
| 287 | - $this->maybe_update_post_fields( $form ); |
|
| 288 | - } |
|
| 285 | + // If there's a post associated with the entry, process post fields |
|
| 286 | + if( !empty( $this->entry['post_id'] ) ) { |
|
| 287 | + $this->maybe_update_post_fields( $form ); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - // Perform actions normally performed after updating a lead |
|
| 291 | - $this->after_update(); |
|
| 290 | + // Perform actions normally performed after updating a lead |
|
| 291 | + $this->after_update(); |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
| 295 | - * @param array $form Gravity Forms form array |
|
| 296 | - * @param string $entry_id Numeric ID of the entry that was updated |
|
| 297 | - */ |
|
| 298 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 299 | - } |
|
| 293 | + /** |
|
| 294 | + * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
| 295 | + * @param array $form Gravity Forms form array |
|
| 296 | + * @param string $entry_id Numeric ID of the entry that was updated |
|
| 297 | + */ |
|
| 298 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - } // process_save |
|
| 301 | + } // process_save |
|
| 302 | 302 | |
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * Have GF handle file uploads |
|
| 306 | - * |
|
| 307 | - * Copy of code from GFFormDisplay::process_form() |
|
| 308 | - * |
|
| 309 | - * @param int $form_id |
|
| 310 | - */ |
|
| 311 | - function process_save_process_files( $form_id ) { |
|
| 304 | + /** |
|
| 305 | + * Have GF handle file uploads |
|
| 306 | + * |
|
| 307 | + * Copy of code from GFFormDisplay::process_form() |
|
| 308 | + * |
|
| 309 | + * @param int $form_id |
|
| 310 | + */ |
|
| 311 | + function process_save_process_files( $form_id ) { |
|
| 312 | 312 | |
| 313 | - //Loading files that have been uploaded to temp folder |
|
| 314 | - $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
| 315 | - if ( ! is_array( $files ) ) { |
|
| 316 | - $files = array(); |
|
| 317 | - } |
|
| 313 | + //Loading files that have been uploaded to temp folder |
|
| 314 | + $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
| 315 | + if ( ! is_array( $files ) ) { |
|
| 316 | + $files = array(); |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
| 320 | - } |
|
| 319 | + RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
| 324 | - * Late validation done on self::custom_validation |
|
| 325 | - * |
|
| 326 | - * @param $plupload_init array Plupload settings |
|
| 327 | - * @param $form_id |
|
| 328 | - * @param $instance |
|
| 329 | - * @return mixed |
|
| 330 | - */ |
|
| 331 | - public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
| 332 | - if( ! $this->is_edit_entry() ) { |
|
| 333 | - return $plupload_init; |
|
| 334 | - } |
|
| 322 | + /** |
|
| 323 | + * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
| 324 | + * Late validation done on self::custom_validation |
|
| 325 | + * |
|
| 326 | + * @param $plupload_init array Plupload settings |
|
| 327 | + * @param $form_id |
|
| 328 | + * @param $instance |
|
| 329 | + * @return mixed |
|
| 330 | + */ |
|
| 331 | + public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
| 332 | + if( ! $this->is_edit_entry() ) { |
|
| 333 | + return $plupload_init; |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - $plupload_init['gf_vars']['max_files'] = 0; |
|
| 336 | + $plupload_init['gf_vars']['max_files'] = 0; |
|
| 337 | 337 | |
| 338 | - return $plupload_init; |
|
| 339 | - } |
|
| 338 | + return $plupload_init; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * Unset adminOnly and convert field input key to string |
|
| 344 | - * @return array $form |
|
| 345 | - */ |
|
| 346 | - private function form_prepare_for_save() { |
|
| 347 | - $form = $this->form; |
|
| 342 | + /** |
|
| 343 | + * Unset adminOnly and convert field input key to string |
|
| 344 | + * @return array $form |
|
| 345 | + */ |
|
| 346 | + private function form_prepare_for_save() { |
|
| 347 | + $form = $this->form; |
|
| 348 | 348 | |
| 349 | - foreach( $form['fields'] as &$field ) { |
|
| 349 | + foreach( $form['fields'] as &$field ) { |
|
| 350 | 350 | |
| 351 | - $field->adminOnly = false; |
|
| 351 | + $field->adminOnly = false; |
|
| 352 | 352 | |
| 353 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 354 | - foreach( $field->inputs as $key => $input ) { |
|
| 355 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - } |
|
| 353 | + if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 354 | + foreach( $field->inputs as $key => $input ) { |
|
| 355 | + $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - return $form; |
|
| 361 | - } |
|
| 360 | + return $form; |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | 363 | |
| 364 | - /** |
|
| 365 | - * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
| 366 | - * |
|
| 367 | - * @param array $form Gravity Forms form |
|
| 368 | - * |
|
| 369 | - * @return void |
|
| 370 | - */ |
|
| 371 | - function maybe_update_post_fields( $form ) { |
|
| 364 | + /** |
|
| 365 | + * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
| 366 | + * |
|
| 367 | + * @param array $form Gravity Forms form |
|
| 368 | + * |
|
| 369 | + * @return void |
|
| 370 | + */ |
|
| 371 | + function maybe_update_post_fields( $form ) { |
|
| 372 | 372 | |
| 373 | - $post_id = $this->entry['post_id']; |
|
| 373 | + $post_id = $this->entry['post_id']; |
|
| 374 | 374 | |
| 375 | - // Security check |
|
| 376 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 377 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 378 | - return; |
|
| 379 | - } |
|
| 375 | + // Security check |
|
| 376 | + if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 377 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 378 | + return; |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | - $update_entry = false; |
|
| 381 | + $update_entry = false; |
|
| 382 | 382 | |
| 383 | - $updated_post = $original_post = get_post( $post_id ); |
|
| 383 | + $updated_post = $original_post = get_post( $post_id ); |
|
| 384 | 384 | |
| 385 | - foreach ( $this->entry as $field_id => $value ) { |
|
| 385 | + foreach ( $this->entry as $field_id => $value ) { |
|
| 386 | 386 | |
| 387 | - //todo: only run through the edit entry configured fields |
|
| 387 | + //todo: only run through the edit entry configured fields |
|
| 388 | 388 | |
| 389 | - $field = RGFormsModel::get_field( $form, $field_id ); |
|
| 389 | + $field = RGFormsModel::get_field( $form, $field_id ); |
|
| 390 | 390 | |
| 391 | - if( class_exists('GF_Fields') ) { |
|
| 392 | - $field = GF_Fields::create( $field ); |
|
| 393 | - } |
|
| 391 | + if( class_exists('GF_Fields') ) { |
|
| 392 | + $field = GF_Fields::create( $field ); |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 395 | + if( GFCommon::is_post_field( $field ) ) { |
|
| 396 | 396 | |
| 397 | - // Get the value of the field, including $_POSTed value |
|
| 398 | - $value = RGFormsModel::get_field_value( $field ); |
|
| 397 | + // Get the value of the field, including $_POSTed value |
|
| 398 | + $value = RGFormsModel::get_field_value( $field ); |
|
| 399 | 399 | |
| 400 | - // Convert the field object in 1.9 to an array for backward compatibility |
|
| 401 | - $field_array = GVCommon::get_field_array( $field ); |
|
| 400 | + // Convert the field object in 1.9 to an array for backward compatibility |
|
| 401 | + $field_array = GVCommon::get_field_array( $field ); |
|
| 402 | 402 | |
| 403 | - switch( $field_array['type'] ) { |
|
| 403 | + switch( $field_array['type'] ) { |
|
| 404 | 404 | |
| 405 | - case 'post_title': |
|
| 406 | - case 'post_content': |
|
| 407 | - case 'post_excerpt': |
|
| 408 | - $updated_post->{$field_array['type']} = $value; |
|
| 409 | - break; |
|
| 410 | - case 'post_tags': |
|
| 411 | - wp_set_post_tags( $post_id, $value, false ); |
|
| 412 | - break; |
|
| 413 | - case 'post_category': |
|
| 405 | + case 'post_title': |
|
| 406 | + case 'post_content': |
|
| 407 | + case 'post_excerpt': |
|
| 408 | + $updated_post->{$field_array['type']} = $value; |
|
| 409 | + break; |
|
| 410 | + case 'post_tags': |
|
| 411 | + wp_set_post_tags( $post_id, $value, false ); |
|
| 412 | + break; |
|
| 413 | + case 'post_category': |
|
| 414 | 414 | |
| 415 | - $categories = is_array( $value ) ? array_values( $value ) : (array)$value; |
|
| 416 | - $categories = array_filter( $categories ); |
|
| 415 | + $categories = is_array( $value ) ? array_values( $value ) : (array)$value; |
|
| 416 | + $categories = array_filter( $categories ); |
|
| 417 | 417 | |
| 418 | - wp_set_post_categories( $post_id, $categories, false ); |
|
| 418 | + wp_set_post_categories( $post_id, $categories, false ); |
|
| 419 | 419 | |
| 420 | - // prepare value to be saved in the entry |
|
| 421 | - $field = GFCommon::add_categories_as_choices( $field, '' ); |
|
| 420 | + // prepare value to be saved in the entry |
|
| 421 | + $field = GFCommon::add_categories_as_choices( $field, '' ); |
|
| 422 | 422 | |
| 423 | - // if post_category is type checkbox, then value is an array of inputs |
|
| 424 | - if( isset( $value[ strval( $field_id ) ] ) ) { |
|
| 425 | - foreach( $value as $input_id => $val ) { |
|
| 426 | - $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 427 | - $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); |
|
| 428 | - } |
|
| 429 | - } else { |
|
| 430 | - $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
|
| 431 | - $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); |
|
| 432 | - } |
|
| 423 | + // if post_category is type checkbox, then value is an array of inputs |
|
| 424 | + if( isset( $value[ strval( $field_id ) ] ) ) { |
|
| 425 | + foreach( $value as $input_id => $val ) { |
|
| 426 | + $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 427 | + $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); |
|
| 428 | + } |
|
| 429 | + } else { |
|
| 430 | + $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
|
| 431 | + $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); |
|
| 432 | + } |
|
| 433 | 433 | |
| 434 | - break; |
|
| 435 | - case 'post_custom_field': |
|
| 434 | + break; |
|
| 435 | + case 'post_custom_field': |
|
| 436 | 436 | |
| 437 | - $input_type = RGFormsModel::get_input_type( $field ); |
|
| 438 | - $custom_field_name = $field_array['postCustomFieldName']; |
|
| 437 | + $input_type = RGFormsModel::get_input_type( $field ); |
|
| 438 | + $custom_field_name = $field_array['postCustomFieldName']; |
|
| 439 | 439 | |
| 440 | - // Only certain custom field types are supported |
|
| 441 | - if( !in_array( $input_type, array( 'list', 'fileupload' ) ) ) { |
|
| 442 | - update_post_meta( $post_id, $custom_field_name, $value ); |
|
| 443 | - } |
|
| 440 | + // Only certain custom field types are supported |
|
| 441 | + if( !in_array( $input_type, array( 'list', 'fileupload' ) ) ) { |
|
| 442 | + update_post_meta( $post_id, $custom_field_name, $value ); |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | - break; |
|
| 445 | + break; |
|
| 446 | 446 | |
| 447 | - case 'post_image': |
|
| 447 | + case 'post_image': |
|
| 448 | 448 | |
| 449 | - $value = ''; |
|
| 450 | - break; |
|
| 449 | + $value = ''; |
|
| 450 | + break; |
|
| 451 | 451 | |
| 452 | - } |
|
| 452 | + } |
|
| 453 | 453 | |
| 454 | - //ignore fields that have not changed |
|
| 455 | - if ( $value === rgget( (string) $field_id, $this->entry ) ) { |
|
| 456 | - continue; |
|
| 457 | - } |
|
| 454 | + //ignore fields that have not changed |
|
| 455 | + if ( $value === rgget( (string) $field_id, $this->entry ) ) { |
|
| 456 | + continue; |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | - // update entry |
|
| 460 | - if( 'post_category' !== $field->type ) { |
|
| 461 | - $this->entry[ strval( $field_id ) ] = $value; |
|
| 462 | - } |
|
| 459 | + // update entry |
|
| 460 | + if( 'post_category' !== $field->type ) { |
|
| 461 | + $this->entry[ strval( $field_id ) ] = $value; |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - $update_entry = true; |
|
| 464 | + $update_entry = true; |
|
| 465 | 465 | |
| 466 | - } |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | - } |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | - if( $update_entry ) { |
|
| 470 | + if( $update_entry ) { |
|
| 471 | 471 | |
| 472 | - $return_entry = GFAPI::update_entry( $this->entry ); |
|
| 472 | + $return_entry = GFAPI::update_entry( $this->entry ); |
|
| 473 | 473 | |
| 474 | - if( is_wp_error( $return_entry ) ) { |
|
| 475 | - do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
|
| 476 | - } else { |
|
| 477 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 478 | - } |
|
| 474 | + if( is_wp_error( $return_entry ) ) { |
|
| 475 | + do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
|
| 476 | + } else { |
|
| 477 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - } |
|
| 480 | + } |
|
| 481 | 481 | |
| 482 | - $return_post = wp_update_post( $updated_post, true ); |
|
| 482 | + $return_post = wp_update_post( $updated_post, true ); |
|
| 483 | 483 | |
| 484 | - if( is_wp_error( $return_post ) ) { |
|
| 485 | - do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
|
| 486 | - } else { |
|
| 487 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded' ); |
|
| 488 | - } |
|
| 484 | + if( is_wp_error( $return_post ) ) { |
|
| 485 | + do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
|
| 486 | + } else { |
|
| 487 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded' ); |
|
| 488 | + } |
|
| 489 | 489 | |
| 490 | - } |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | - /** |
|
| 493 | - * Perform actions normally performed after updating a lead |
|
| 494 | - * |
|
| 495 | - * @since 1.8 |
|
| 496 | - * |
|
| 497 | - * @see GFEntryDetail::lead_detail_page() |
|
| 498 | - * |
|
| 499 | - * @return void |
|
| 500 | - */ |
|
| 501 | - function after_update() { |
|
| 492 | + /** |
|
| 493 | + * Perform actions normally performed after updating a lead |
|
| 494 | + * |
|
| 495 | + * @since 1.8 |
|
| 496 | + * |
|
| 497 | + * @see GFEntryDetail::lead_detail_page() |
|
| 498 | + * |
|
| 499 | + * @return void |
|
| 500 | + */ |
|
| 501 | + function after_update() { |
|
| 502 | 502 | |
| 503 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
| 504 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 503 | + do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
| 504 | + do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 505 | 505 | |
| 506 | - // Re-define the entry now that we've updated it. |
|
| 507 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 506 | + // Re-define the entry now that we've updated it. |
|
| 507 | + $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 508 | 508 | |
| 509 | - $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
| 509 | + $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
| 510 | 510 | |
| 511 | - // We need to clear the cache because Gravity Forms caches the field values, which |
|
| 512 | - // we have just updated. |
|
| 513 | - foreach ($this->form['fields'] as $key => $field) { |
|
| 514 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 515 | - } |
|
| 511 | + // We need to clear the cache because Gravity Forms caches the field values, which |
|
| 512 | + // we have just updated. |
|
| 513 | + foreach ($this->form['fields'] as $key => $field) { |
|
| 514 | + GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | - $this->entry = $entry; |
|
| 518 | - } |
|
| 517 | + $this->entry = $entry; |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | 520 | |
| 521 | - /** |
|
| 522 | - * Display the Edit Entry form |
|
| 523 | - * |
|
| 524 | - * @return [type] [description] |
|
| 525 | - */ |
|
| 526 | - public function edit_entry_form() { |
|
| 521 | + /** |
|
| 522 | + * Display the Edit Entry form |
|
| 523 | + * |
|
| 524 | + * @return [type] [description] |
|
| 525 | + */ |
|
| 526 | + public function edit_entry_form() { |
|
| 527 | 527 | |
| 528 | - $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
| 528 | + $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
| 529 | 529 | |
| 530 | - ?> |
|
| 530 | + ?> |
|
| 531 | 531 | |
| 532 | 532 | <div class="gv-edit-entry-wrapper"><?php |
| 533 | 533 | |
| 534 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 534 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 535 | 535 | |
| 536 | - /** |
|
| 537 | - * Fixes weird wpautop() issue |
|
| 538 | - * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
| 539 | - */ |
|
| 540 | - echo gravityview_strip_whitespace( $javascript ); |
|
| 536 | + /** |
|
| 537 | + * Fixes weird wpautop() issue |
|
| 538 | + * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
| 539 | + */ |
|
| 540 | + echo gravityview_strip_whitespace( $javascript ); |
|
| 541 | 541 | |
| 542 | - ?><h2 class="gv-edit-entry-title"> |
|
| 542 | + ?><h2 class="gv-edit-entry-title"> |
|
| 543 | 543 | <span><?php |
| 544 | 544 | |
| 545 | - /** |
|
| 546 | - * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 547 | - * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 548 | - * @param GravityView_Edit_Entry_Render $this This object |
|
| 549 | - */ |
|
| 550 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 545 | + /** |
|
| 546 | + * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 547 | + * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 548 | + * @param GravityView_Edit_Entry_Render $this This object |
|
| 549 | + */ |
|
| 550 | + $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 551 | 551 | |
| 552 | - echo esc_attr( $edit_entry_title ); |
|
| 553 | - ?></span> |
|
| 552 | + echo esc_attr( $edit_entry_title ); |
|
| 553 | + ?></span> |
|
| 554 | 554 | </h2> |
| 555 | 555 | |
| 556 | 556 | <?php |
| 557 | 557 | |
| 558 | - // Display the success message |
|
| 559 | - if( rgpost('action') === 'update' ) { |
|
| 558 | + // Display the success message |
|
| 559 | + if( rgpost('action') === 'update' ) { |
|
| 560 | 560 | |
| 561 | - if( ! $this->is_valid ){ |
|
| 561 | + if( ! $this->is_valid ){ |
|
| 562 | 562 | |
| 563 | - // Keeping this compatible with Gravity Forms. |
|
| 564 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 565 | - $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 563 | + // Keeping this compatible with Gravity Forms. |
|
| 564 | + $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 565 | + $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 566 | 566 | |
| 567 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 567 | + echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 568 | 568 | |
| 569 | - } else { |
|
| 570 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 569 | + } else { |
|
| 570 | + $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 571 | 571 | |
| 572 | - /** |
|
| 573 | - * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
| 574 | - * @since 1.5.4 |
|
| 575 | - * @param string $entry_updated_message Existing message |
|
| 576 | - * @param int $view_id View ID |
|
| 577 | - * @param array $entry Gravity Forms entry array |
|
| 578 | - * @param string $back_link URL to return to the original entry. @since 1.6 |
|
| 579 | - */ |
|
| 580 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 572 | + /** |
|
| 573 | + * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
| 574 | + * @since 1.5.4 |
|
| 575 | + * @param string $entry_updated_message Existing message |
|
| 576 | + * @param int $view_id View ID |
|
| 577 | + * @param array $entry Gravity Forms entry array |
|
| 578 | + * @param string $back_link URL to return to the original entry. @since 1.6 |
|
| 579 | + */ |
|
| 580 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 581 | 581 | |
| 582 | - echo GVCommon::generate_notice( $message ); |
|
| 583 | - } |
|
| 582 | + echo GVCommon::generate_notice( $message ); |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | - } |
|
| 585 | + } |
|
| 586 | 586 | |
| 587 | - ?> |
|
| 587 | + ?> |
|
| 588 | 588 | |
| 589 | 589 | <?php // The ID of the form needs to be `gform_{form_id}` for the pluploader ?> |
| 590 | 590 | |
@@ -592,590 +592,590 @@ discard block |
||
| 592 | 592 | |
| 593 | 593 | <?php |
| 594 | 594 | |
| 595 | - wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
| 595 | + wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
| 596 | 596 | |
| 597 | - wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
| 597 | + wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
| 598 | 598 | |
| 599 | - // Most of this is needed for GFFormDisplay::validate(), but `gform_unique_id` is needed for file cleanup. |
|
| 599 | + // Most of this is needed for GFFormDisplay::validate(), but `gform_unique_id` is needed for file cleanup. |
|
| 600 | 600 | |
| 601 | - ?> |
|
| 601 | + ?> |
|
| 602 | 602 | |
| 603 | 603 | |
| 604 | 604 | <?php |
| 605 | 605 | |
| 606 | - /** |
|
| 607 | - * By default, the lead_detail_edit method uses the `RGFormsModel::get_lead_field_value()` method, which doesn't fill in $_POST values when there is a validation error, because it was designed to work in the admin. We want to use the `RGFormsModel::get_field_value()` If the form has been submitted, use the values for the fields. |
|
| 608 | - */ |
|
| 609 | - //add_filter( 'gform_get_field_value', array( $this, 'get_field_value' ), 10, 3 ); |
|
| 606 | + /** |
|
| 607 | + * By default, the lead_detail_edit method uses the `RGFormsModel::get_lead_field_value()` method, which doesn't fill in $_POST values when there is a validation error, because it was designed to work in the admin. We want to use the `RGFormsModel::get_field_value()` If the form has been submitted, use the values for the fields. |
|
| 608 | + */ |
|
| 609 | + //add_filter( 'gform_get_field_value', array( $this, 'get_field_value' ), 10, 3 ); |
|
| 610 | 610 | |
| 611 | - // Print the actual form HTML |
|
| 612 | - $this->render_edit_form(); |
|
| 611 | + // Print the actual form HTML |
|
| 612 | + $this->render_edit_form(); |
|
| 613 | 613 | |
| 614 | - //echo $this->render_form_buttons(); |
|
| 614 | + //echo $this->render_form_buttons(); |
|
| 615 | 615 | |
| 616 | - ?> |
|
| 616 | + ?> |
|
| 617 | 617 | </form> |
| 618 | 618 | |
| 619 | 619 | </div> |
| 620 | 620 | |
| 621 | 621 | <?php |
| 622 | - } |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Display the Edit Entry form in the original Gravity Forms format |
|
| 626 | - * |
|
| 627 | - * @since 1.9 |
|
| 628 | - * |
|
| 629 | - * @param $form |
|
| 630 | - * @param $lead |
|
| 631 | - * @param $view_id |
|
| 632 | - * |
|
| 633 | - * @return void |
|
| 634 | - */ |
|
| 635 | - private function render_edit_form() { |
|
| 636 | - |
|
| 637 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 638 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 639 | - add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 640 | - add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
| 641 | - |
|
| 642 | - // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
| 643 | - unset( $_GET['page'] ); |
|
| 644 | - |
|
| 645 | - // TODO: Make sure validation isn't handled by GF |
|
| 646 | - // TODO: Include CSS for file upload fields |
|
| 647 | - // TODO: Verify multiple-page forms |
|
| 648 | - // TODO: Product fields are not editable |
|
| 649 | - // TODO: Check Updated and Error messages |
|
| 650 | - |
|
| 651 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 652 | - |
|
| 653 | - remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 654 | - remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 655 | - remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 656 | - remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
| 657 | - |
|
| 658 | - echo $html; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
| 663 | - * @since 1.8 |
|
| 664 | - * @return string |
|
| 665 | - */ |
|
| 666 | - public function render_form_buttons() { |
|
| 667 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
| 673 | - * |
|
| 674 | - * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
| 675 | - * |
|
| 676 | - * @param array $form |
|
| 677 | - * @param boolean $ajax Whether in AJAX mode |
|
| 678 | - * @param array|string $field_values Passed parameters to the form |
|
| 679 | - * |
|
| 680 | - * @since 1.9 |
|
| 681 | - * |
|
| 682 | - * @return array Modified form array |
|
| 683 | - */ |
|
| 684 | - public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
| 685 | - |
|
| 686 | - // In case we have validated the form, use it to inject the validation results into the form render |
|
| 687 | - if( isset( $this->form_after_validation ) ) { |
|
| 688 | - $form = $this->form_after_validation; |
|
| 689 | - } else { |
|
| 690 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - $form = $this->filter_conditional_logic( $form ); |
|
| 694 | - |
|
| 695 | - // for now we don't support Save and Continue feature. |
|
| 696 | - if( ! self::$supports_save_and_continue ) { |
|
| 697 | - unset( $form['save'] ); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - return $form; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * |
|
| 706 | - * Fill-in the saved values into the form inputs |
|
| 707 | - * |
|
| 708 | - * @param string $field_content Always empty. |
|
| 709 | - * @param GF_Field $field |
|
| 710 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 711 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 712 | - * @param int $form_id Form ID |
|
| 713 | - * |
|
| 714 | - * @return mixed |
|
| 715 | - */ |
|
| 716 | - function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 717 | - |
|
| 718 | - // If the form has been submitted, then we don't need to pre-fill the values, |
|
| 719 | - // Except for fileupload type - run always!! |
|
| 720 | - if( |
|
| 721 | - $this->is_edit_entry_submission() && 'fileupload' !== $field->type |
|
| 722 | - || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
| 723 | - ) { |
|
| 724 | - return $field_content; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - // Turn on Admin-style display for file upload fields only |
|
| 728 | - if( 'fileupload' === $field->type ) { |
|
| 729 | - $_GET['page'] = 'gf_entries'; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
| 733 | - $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
| 734 | - |
|
| 735 | - // add categories as choices for Post Category field |
|
| 736 | - if ( 'post_category' === $field->type ) { |
|
| 737 | - $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * @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. |
|
| 742 | - * @param boolean True: override saved values; False: don't override (default) |
|
| 743 | - * @param $field GF_Field object Gravity Forms field object |
|
| 744 | - * @since 1.13 |
|
| 745 | - */ |
|
| 746 | - $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
| 747 | - |
|
| 748 | - // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
| 749 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 750 | - |
|
| 751 | - $field_value = array(); |
|
| 752 | - |
|
| 753 | - // only accept pre-populated values if the field doesn't have any choice selected. |
|
| 754 | - $allow_pre_populated = $field->allowsPrepopulate; |
|
| 755 | - |
|
| 756 | - foreach ( (array)$field->inputs as $input ) { |
|
| 757 | - |
|
| 758 | - $input_id = strval( $input['id'] ); |
|
| 759 | - |
|
| 760 | - if ( ! empty( $this->entry[ $input_id ] ) ) { |
|
| 761 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 762 | - $allow_pre_populated = false; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - $pre_value = $field->get_value_submission( array(), false ); |
|
| 768 | - |
|
| 769 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !empty( $pre_value ) ) ? $field_value : $pre_value; |
|
| 770 | - |
|
| 771 | - } else { |
|
| 772 | - |
|
| 773 | - $id = intval( $field->id ); |
|
| 774 | - |
|
| 775 | - // get pre-populated value if exists |
|
| 776 | - $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
| 777 | - |
|
| 778 | - // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
| 779 | - // or pre-populated value if not empty and set to override saved value |
|
| 780 | - $field_value = !empty( $this->entry[ $id ] ) && ! ( $override_saved_value && !empty( $pre_value ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 781 | - |
|
| 782 | - // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
| 783 | - if ( 'post_category' === $field->type && !empty( $field_value ) ) { |
|
| 784 | - $categories = array(); |
|
| 785 | - foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
| 786 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 787 | - } |
|
| 788 | - $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
| 789 | - } |
|
| 622 | + } |
|
| 790 | 623 | |
| 791 | - } |
|
| 624 | + /** |
|
| 625 | + * Display the Edit Entry form in the original Gravity Forms format |
|
| 626 | + * |
|
| 627 | + * @since 1.9 |
|
| 628 | + * |
|
| 629 | + * @param $form |
|
| 630 | + * @param $lead |
|
| 631 | + * @param $view_id |
|
| 632 | + * |
|
| 633 | + * @return void |
|
| 634 | + */ |
|
| 635 | + private function render_edit_form() { |
|
| 792 | 636 | |
| 793 | - // if value is empty get the default value if defined |
|
| 794 | - $field_value = $field->get_value_default_if_empty( $field_value ); |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 798 | - * @since 1.11 |
|
| 799 | - * @param mixed $field_value field value used to populate the input |
|
| 800 | - * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 801 | - */ |
|
| 802 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
| 803 | - |
|
| 804 | - // Prevent any PHP warnings, like undefined index |
|
| 805 | - ob_start(); |
|
| 806 | - |
|
| 807 | - $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 808 | - |
|
| 809 | - // If there was output, it's an error |
|
| 810 | - $warnings = ob_get_clean(); |
|
| 637 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 638 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 639 | + add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 640 | + add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
| 811 | 641 | |
| 812 | - if( !empty( $warnings ) ) { |
|
| 813 | - do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
| 814 | - } |
|
| 642 | + // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
| 643 | + unset( $_GET['page'] ); |
|
| 815 | 644 | |
| 816 | - /** |
|
| 817 | - * Unset hack $_GET['page'] = 'gf_entries' |
|
| 818 | - * We need the fileupload html field to render with the proper id |
|
| 819 | - * ( <li id="field_80_16" ... > ) |
|
| 820 | - */ |
|
| 821 | - unset( $_GET['page'] ); |
|
| 645 | + // TODO: Make sure validation isn't handled by GF |
|
| 646 | + // TODO: Include CSS for file upload fields |
|
| 647 | + // TODO: Verify multiple-page forms |
|
| 648 | + // TODO: Product fields are not editable |
|
| 649 | + // TODO: Check Updated and Error messages |
|
| 822 | 650 | |
| 823 | - return $return; |
|
| 824 | - } |
|
| 651 | + $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 825 | 652 | |
| 653 | + remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 654 | + remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 655 | + remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 656 | + remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
| 826 | 657 | |
| 827 | - /** |
|
| 828 | - * Get the posted values from the edit form submission |
|
| 829 | - * |
|
| 830 | - * @hack |
|
| 831 | - * @uses GFFormsModel::get_field_value() |
|
| 832 | - * @param mixed $value Existing field value, before edit |
|
| 833 | - * @param array $lead Gravity Forms entry array |
|
| 834 | - * @param array $field Gravity Forms field array |
|
| 835 | - * @return string [description] |
|
| 836 | - */ |
|
| 837 | - public function get_field_value( $value, $lead, $field ) { |
|
| 658 | + echo $html; |
|
| 659 | + } |
|
| 838 | 660 | |
| 839 | - // The form's not being edited; use the original value |
|
| 840 | - if( ! $this->is_edit_entry_submission() ) { |
|
| 841 | - return $value; |
|
| 842 | - } |
|
| 661 | + /** |
|
| 662 | + * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
| 663 | + * @since 1.8 |
|
| 664 | + * @return string |
|
| 665 | + */ |
|
| 666 | + public function render_form_buttons() { |
|
| 667 | + return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 668 | + } |
|
| 843 | 669 | |
| 844 | - return GFFormsModel::get_field_value( $field, $lead, true ); |
|
| 845 | - } |
|
| 846 | 670 | |
| 671 | + /** |
|
| 672 | + * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
| 673 | + * |
|
| 674 | + * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
| 675 | + * |
|
| 676 | + * @param array $form |
|
| 677 | + * @param boolean $ajax Whether in AJAX mode |
|
| 678 | + * @param array|string $field_values Passed parameters to the form |
|
| 679 | + * |
|
| 680 | + * @since 1.9 |
|
| 681 | + * |
|
| 682 | + * @return array Modified form array |
|
| 683 | + */ |
|
| 684 | + public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
| 685 | + |
|
| 686 | + // In case we have validated the form, use it to inject the validation results into the form render |
|
| 687 | + if( isset( $this->form_after_validation ) ) { |
|
| 688 | + $form = $this->form_after_validation; |
|
| 689 | + } else { |
|
| 690 | + $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 691 | + } |
|
| 847 | 692 | |
| 693 | + $form = $this->filter_conditional_logic( $form ); |
|
| 848 | 694 | |
| 695 | + // for now we don't support Save and Continue feature. |
|
| 696 | + if( ! self::$supports_save_and_continue ) { |
|
| 697 | + unset( $form['save'] ); |
|
| 698 | + } |
|
| 849 | 699 | |
| 850 | - // ---- Entry validation |
|
| 700 | + return $form; |
|
| 701 | + } |
|
| 851 | 702 | |
| 852 | - /** |
|
| 853 | - * Add field keys that Gravity Forms expects. |
|
| 854 | - * |
|
| 855 | - * @see GFFormDisplay::validate() |
|
| 856 | - * @param array $form GF Form |
|
| 857 | - * @return array Modified GF Form |
|
| 858 | - */ |
|
| 859 | - function gform_pre_validation( $form ) { |
|
| 860 | 703 | |
| 861 | - if( ! $this->verify_nonce() ) { |
|
| 862 | - return $form; |
|
| 863 | - } |
|
| 704 | + /** |
|
| 705 | + * |
|
| 706 | + * Fill-in the saved values into the form inputs |
|
| 707 | + * |
|
| 708 | + * @param string $field_content Always empty. |
|
| 709 | + * @param GF_Field $field |
|
| 710 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 711 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 712 | + * @param int $form_id Form ID |
|
| 713 | + * |
|
| 714 | + * @return mixed |
|
| 715 | + */ |
|
| 716 | + function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 717 | + |
|
| 718 | + // If the form has been submitted, then we don't need to pre-fill the values, |
|
| 719 | + // Except for fileupload type - run always!! |
|
| 720 | + if( |
|
| 721 | + $this->is_edit_entry_submission() && 'fileupload' !== $field->type |
|
| 722 | + || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
| 723 | + ) { |
|
| 724 | + return $field_content; |
|
| 725 | + } |
|
| 864 | 726 | |
| 865 | - // Fix PHP warning regarding undefined index. |
|
| 866 | - foreach ( $form['fields'] as &$field) { |
|
| 727 | + // Turn on Admin-style display for file upload fields only |
|
| 728 | + if( 'fileupload' === $field->type ) { |
|
| 729 | + $_GET['page'] = 'gf_entries'; |
|
| 730 | + } |
|
| 867 | 731 | |
| 868 | - // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
| 869 | - // expects certain field array items to be set. |
|
| 870 | - foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
| 871 | - $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 872 | - } |
|
| 732 | + // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
| 733 | + $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
| 734 | + |
|
| 735 | + // add categories as choices for Post Category field |
|
| 736 | + if ( 'post_category' === $field->type ) { |
|
| 737 | + $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * @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. |
|
| 742 | + * @param boolean True: override saved values; False: don't override (default) |
|
| 743 | + * @param $field GF_Field object Gravity Forms field object |
|
| 744 | + * @since 1.13 |
|
| 745 | + */ |
|
| 746 | + $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
| 747 | + |
|
| 748 | + // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
| 749 | + if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 750 | + |
|
| 751 | + $field_value = array(); |
|
| 752 | + |
|
| 753 | + // only accept pre-populated values if the field doesn't have any choice selected. |
|
| 754 | + $allow_pre_populated = $field->allowsPrepopulate; |
|
| 755 | + |
|
| 756 | + foreach ( (array)$field->inputs as $input ) { |
|
| 757 | + |
|
| 758 | + $input_id = strval( $input['id'] ); |
|
| 759 | + |
|
| 760 | + if ( ! empty( $this->entry[ $input_id ] ) ) { |
|
| 761 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 762 | + $allow_pre_populated = false; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + $pre_value = $field->get_value_submission( array(), false ); |
|
| 768 | + |
|
| 769 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !empty( $pre_value ) ) ? $field_value : $pre_value; |
|
| 770 | + |
|
| 771 | + } else { |
|
| 772 | + |
|
| 773 | + $id = intval( $field->id ); |
|
| 774 | + |
|
| 775 | + // get pre-populated value if exists |
|
| 776 | + $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
| 777 | + |
|
| 778 | + // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
| 779 | + // or pre-populated value if not empty and set to override saved value |
|
| 780 | + $field_value = !empty( $this->entry[ $id ] ) && ! ( $override_saved_value && !empty( $pre_value ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 781 | + |
|
| 782 | + // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
| 783 | + if ( 'post_category' === $field->type && !empty( $field_value ) ) { |
|
| 784 | + $categories = array(); |
|
| 785 | + foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
| 786 | + $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 787 | + } |
|
| 788 | + $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + } |
|
| 873 | 792 | |
| 874 | - // unset emailConfirmEnabled for email type fields |
|
| 875 | - /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
| 793 | + // if value is empty get the default value if defined |
|
| 794 | + $field_value = $field->get_value_default_if_empty( $field_value ); |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 798 | + * @since 1.11 |
|
| 799 | + * @param mixed $field_value field value used to populate the input |
|
| 800 | + * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 801 | + */ |
|
| 802 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
| 803 | + |
|
| 804 | + // Prevent any PHP warnings, like undefined index |
|
| 805 | + ob_start(); |
|
| 806 | + |
|
| 807 | + $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 808 | + |
|
| 809 | + // If there was output, it's an error |
|
| 810 | + $warnings = ob_get_clean(); |
|
| 811 | + |
|
| 812 | + if( !empty( $warnings ) ) { |
|
| 813 | + do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * Unset hack $_GET['page'] = 'gf_entries' |
|
| 818 | + * We need the fileupload html field to render with the proper id |
|
| 819 | + * ( <li id="field_80_16" ... > ) |
|
| 820 | + */ |
|
| 821 | + unset( $_GET['page'] ); |
|
| 822 | + |
|
| 823 | + return $return; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Get the posted values from the edit form submission |
|
| 829 | + * |
|
| 830 | + * @hack |
|
| 831 | + * @uses GFFormsModel::get_field_value() |
|
| 832 | + * @param mixed $value Existing field value, before edit |
|
| 833 | + * @param array $lead Gravity Forms entry array |
|
| 834 | + * @param array $field Gravity Forms field array |
|
| 835 | + * @return string [description] |
|
| 836 | + */ |
|
| 837 | + public function get_field_value( $value, $lead, $field ) { |
|
| 838 | + |
|
| 839 | + // The form's not being edited; use the original value |
|
| 840 | + if( ! $this->is_edit_entry_submission() ) { |
|
| 841 | + return $value; |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + return GFFormsModel::get_field_value( $field, $lead, true ); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + // ---- Entry validation |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * Add field keys that Gravity Forms expects. |
|
| 854 | + * |
|
| 855 | + * @see GFFormDisplay::validate() |
|
| 856 | + * @param array $form GF Form |
|
| 857 | + * @return array Modified GF Form |
|
| 858 | + */ |
|
| 859 | + function gform_pre_validation( $form ) { |
|
| 860 | + |
|
| 861 | + if( ! $this->verify_nonce() ) { |
|
| 862 | + return $form; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + // Fix PHP warning regarding undefined index. |
|
| 866 | + foreach ( $form['fields'] as &$field) { |
|
| 867 | + |
|
| 868 | + // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
| 869 | + // expects certain field array items to be set. |
|
| 870 | + foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
| 871 | + $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + // unset emailConfirmEnabled for email type fields |
|
| 875 | + /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
| 876 | 876 | $field['emailConfirmEnabled'] = ''; |
| 877 | 877 | }*/ |
| 878 | 878 | |
| 879 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 879 | + switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 880 | 880 | |
| 881 | - /** |
|
| 882 | - * 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. |
|
| 883 | - * |
|
| 884 | - * 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. |
|
| 885 | - * |
|
| 886 | - * @hack |
|
| 887 | - */ |
|
| 888 | - case 'fileupload': |
|
| 889 | - case 'post_image': |
|
| 881 | + /** |
|
| 882 | + * 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. |
|
| 883 | + * |
|
| 884 | + * 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. |
|
| 885 | + * |
|
| 886 | + * @hack |
|
| 887 | + */ |
|
| 888 | + case 'fileupload': |
|
| 889 | + case 'post_image': |
|
| 890 | 890 | |
| 891 | - // Set the previous value |
|
| 892 | - $entry = $this->get_entry(); |
|
| 891 | + // Set the previous value |
|
| 892 | + $entry = $this->get_entry(); |
|
| 893 | 893 | |
| 894 | - $input_name = 'input_'.$field->id; |
|
| 895 | - $form_id = $form['id']; |
|
| 894 | + $input_name = 'input_'.$field->id; |
|
| 895 | + $form_id = $form['id']; |
|
| 896 | 896 | |
| 897 | - $value = NULL; |
|
| 897 | + $value = NULL; |
|
| 898 | 898 | |
| 899 | - // Use the previous entry value as the default. |
|
| 900 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 901 | - $value = $entry[ $field->id ]; |
|
| 902 | - } |
|
| 899 | + // Use the previous entry value as the default. |
|
| 900 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 901 | + $value = $entry[ $field->id ]; |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - // If this is a single upload file |
|
| 905 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 906 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 907 | - $value = $file_path['url']; |
|
| 904 | + // If this is a single upload file |
|
| 905 | + if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 906 | + $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 907 | + $value = $file_path['url']; |
|
| 908 | 908 | |
| 909 | - } else { |
|
| 909 | + } else { |
|
| 910 | 910 | |
| 911 | - // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 912 | - // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 913 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 911 | + // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 912 | + // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 913 | + $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 914 | 914 | |
| 915 | - } |
|
| 915 | + } |
|
| 916 | 916 | |
| 917 | - if( rgar($field, "multipleFiles") ) { |
|
| 917 | + if( rgar($field, "multipleFiles") ) { |
|
| 918 | 918 | |
| 919 | - // If there are fresh uploads, process and merge them. |
|
| 920 | - // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 921 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 919 | + // If there are fresh uploads, process and merge them. |
|
| 920 | + // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 921 | + if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 922 | 922 | |
| 923 | - $value = empty( $value ) ? '[]' : $value; |
|
| 924 | - $value = stripslashes_deep( $value ); |
|
| 925 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 926 | - } |
|
| 923 | + $value = empty( $value ) ? '[]' : $value; |
|
| 924 | + $value = stripslashes_deep( $value ); |
|
| 925 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 926 | + } |
|
| 927 | 927 | |
| 928 | - } else { |
|
| 928 | + } else { |
|
| 929 | 929 | |
| 930 | - // A file already exists when editing an entry |
|
| 931 | - // We set this to solve issue when file upload fields are required. |
|
| 932 | - GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 930 | + // A file already exists when editing an entry |
|
| 931 | + // We set this to solve issue when file upload fields are required. |
|
| 932 | + GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 933 | 933 | |
| 934 | - } |
|
| 934 | + } |
|
| 935 | 935 | |
| 936 | - $_POST[ $input_name ] = $value; |
|
| 936 | + $_POST[ $input_name ] = $value; |
|
| 937 | 937 | |
| 938 | - break; |
|
| 939 | - case 'number': |
|
| 940 | - // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 941 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 942 | - $_POST['input_'.$field->id ] = NULL; |
|
| 943 | - } |
|
| 944 | - break; |
|
| 945 | - case 'captcha': |
|
| 946 | - // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
| 947 | - $_POST['recaptcha_challenge_field'] = NULL; |
|
| 948 | - $_POST['recaptcha_response_field'] = NULL; |
|
| 949 | - break; |
|
| 950 | - } |
|
| 938 | + break; |
|
| 939 | + case 'number': |
|
| 940 | + // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 941 | + if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 942 | + $_POST['input_'.$field->id ] = NULL; |
|
| 943 | + } |
|
| 944 | + break; |
|
| 945 | + case 'captcha': |
|
| 946 | + // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
| 947 | + $_POST['recaptcha_challenge_field'] = NULL; |
|
| 948 | + $_POST['recaptcha_response_field'] = NULL; |
|
| 949 | + break; |
|
| 950 | + } |
|
| 951 | 951 | |
| 952 | - } |
|
| 952 | + } |
|
| 953 | 953 | |
| 954 | - return $form; |
|
| 955 | - } |
|
| 954 | + return $form; |
|
| 955 | + } |
|
| 956 | 956 | |
| 957 | 957 | |
| 958 | - /** |
|
| 959 | - * Process validation for a edit entry submission |
|
| 960 | - * |
|
| 961 | - * Sets the `is_valid` object var |
|
| 962 | - * |
|
| 963 | - * @return void |
|
| 964 | - */ |
|
| 965 | - function validate() { |
|
| 958 | + /** |
|
| 959 | + * Process validation for a edit entry submission |
|
| 960 | + * |
|
| 961 | + * Sets the `is_valid` object var |
|
| 962 | + * |
|
| 963 | + * @return void |
|
| 964 | + */ |
|
| 965 | + function validate() { |
|
| 966 | 966 | |
| 967 | - // If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
| 968 | - if ( class_exists( 'GFUser' ) ) { |
|
| 969 | - remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
| 970 | - } |
|
| 967 | + // If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
| 968 | + if ( class_exists( 'GFUser' ) ) { |
|
| 969 | + remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
| 970 | + } |
|
| 971 | 971 | |
| 972 | - /** |
|
| 973 | - * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
| 974 | - * You can enter whatever you want! |
|
| 975 | - * We try validating, and customize the results using `self::custom_validation()` |
|
| 976 | - */ |
|
| 977 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 972 | + /** |
|
| 973 | + * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
| 974 | + * You can enter whatever you want! |
|
| 975 | + * We try validating, and customize the results using `self::custom_validation()` |
|
| 976 | + */ |
|
| 977 | + add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 978 | 978 | |
| 979 | - // Needed by the validate funtion |
|
| 980 | - $failed_validation_page = NULL; |
|
| 981 | - $field_values = RGForms::post( 'gform_field_values' ); |
|
| 979 | + // Needed by the validate funtion |
|
| 980 | + $failed_validation_page = NULL; |
|
| 981 | + $field_values = RGForms::post( 'gform_field_values' ); |
|
| 982 | 982 | |
| 983 | - // Prevent entry limit from running when editing an entry, also |
|
| 984 | - // prevent form scheduling from preventing editing |
|
| 985 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 983 | + // Prevent entry limit from running when editing an entry, also |
|
| 984 | + // prevent form scheduling from preventing editing |
|
| 985 | + unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 986 | 986 | |
| 987 | - // Hide fields depending on Edit Entry settings |
|
| 988 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 987 | + // Hide fields depending on Edit Entry settings |
|
| 988 | + $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 989 | 989 | |
| 990 | - $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
| 990 | + $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
| 991 | 991 | |
| 992 | - remove_filter( 'gform_validation_'.$this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 993 | - } |
|
| 992 | + remove_filter( 'gform_validation_'.$this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 993 | + } |
|
| 994 | 994 | |
| 995 | 995 | |
| 996 | - /** |
|
| 997 | - * Make validation work for Edit Entry |
|
| 998 | - * |
|
| 999 | - * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
| 1000 | - * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
| 1001 | - * fields. This goes through all the fields and if they're an invalid post field, we |
|
| 1002 | - * set them as valid. If there are still issues, we'll return false. |
|
| 1003 | - * |
|
| 1004 | - * @param [type] $validation_results [description] |
|
| 1005 | - * @return [type] [description] |
|
| 1006 | - */ |
|
| 1007 | - function custom_validation( $validation_results ) { |
|
| 996 | + /** |
|
| 997 | + * Make validation work for Edit Entry |
|
| 998 | + * |
|
| 999 | + * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
| 1000 | + * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
| 1001 | + * fields. This goes through all the fields and if they're an invalid post field, we |
|
| 1002 | + * set them as valid. If there are still issues, we'll return false. |
|
| 1003 | + * |
|
| 1004 | + * @param [type] $validation_results [description] |
|
| 1005 | + * @return [type] [description] |
|
| 1006 | + */ |
|
| 1007 | + function custom_validation( $validation_results ) { |
|
| 1008 | 1008 | |
| 1009 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1009 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1010 | 1010 | |
| 1011 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1011 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1012 | 1012 | |
| 1013 | - $gv_valid = true; |
|
| 1013 | + $gv_valid = true; |
|
| 1014 | 1014 | |
| 1015 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1015 | + foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1016 | 1016 | |
| 1017 | - $value = RGFormsModel::get_field_value( $field ); |
|
| 1018 | - $field_type = RGFormsModel::get_input_type( $field ); |
|
| 1017 | + $value = RGFormsModel::get_field_value( $field ); |
|
| 1018 | + $field_type = RGFormsModel::get_input_type( $field ); |
|
| 1019 | 1019 | |
| 1020 | - // Validate always |
|
| 1021 | - switch ( $field_type ) { |
|
| 1020 | + // Validate always |
|
| 1021 | + switch ( $field_type ) { |
|
| 1022 | 1022 | |
| 1023 | 1023 | |
| 1024 | - case 'fileupload' : |
|
| 1024 | + case 'fileupload' : |
|
| 1025 | 1025 | |
| 1026 | - // in case nothing is uploaded but there are already files saved |
|
| 1027 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1028 | - $field->failed_validation = false; |
|
| 1029 | - unset( $field->validation_message ); |
|
| 1030 | - } |
|
| 1026 | + // in case nothing is uploaded but there are already files saved |
|
| 1027 | + if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1028 | + $field->failed_validation = false; |
|
| 1029 | + unset( $field->validation_message ); |
|
| 1030 | + } |
|
| 1031 | 1031 | |
| 1032 | - // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1033 | - if( rgar( $field, 'maxFiles') && rgar( $field, 'multipleFiles') ) { |
|
| 1032 | + // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1033 | + if( rgar( $field, 'maxFiles') && rgar( $field, 'multipleFiles') ) { |
|
| 1034 | 1034 | |
| 1035 | - $input_name = 'input_' . $field->id; |
|
| 1036 | - //uploaded |
|
| 1037 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1035 | + $input_name = 'input_' . $field->id; |
|
| 1036 | + //uploaded |
|
| 1037 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1038 | 1038 | |
| 1039 | - //existent |
|
| 1040 | - $entry = $this->get_entry(); |
|
| 1041 | - $value = NULL; |
|
| 1042 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1043 | - $value = json_decode( $entry[ $field->id ], true ); |
|
| 1044 | - } |
|
| 1039 | + //existent |
|
| 1040 | + $entry = $this->get_entry(); |
|
| 1041 | + $value = NULL; |
|
| 1042 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1043 | + $value = json_decode( $entry[ $field->id ], true ); |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | - // count uploaded files and existent entry files |
|
| 1047 | - $count_files = count( $file_names ) + count( $value ); |
|
| 1046 | + // count uploaded files and existent entry files |
|
| 1047 | + $count_files = count( $file_names ) + count( $value ); |
|
| 1048 | 1048 | |
| 1049 | - if( $count_files > $field->maxFiles ) { |
|
| 1050 | - $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1051 | - $field->failed_validation = 1; |
|
| 1052 | - $gv_valid = false; |
|
| 1049 | + if( $count_files > $field->maxFiles ) { |
|
| 1050 | + $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1051 | + $field->failed_validation = 1; |
|
| 1052 | + $gv_valid = false; |
|
| 1053 | 1053 | |
| 1054 | - // in case of error make sure the newest upload files are removed from the upload input |
|
| 1055 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1056 | - } |
|
| 1054 | + // in case of error make sure the newest upload files are removed from the upload input |
|
| 1055 | + GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1056 | + } |
|
| 1057 | 1057 | |
| 1058 | - } |
|
| 1058 | + } |
|
| 1059 | 1059 | |
| 1060 | 1060 | |
| 1061 | - break; |
|
| 1061 | + break; |
|
| 1062 | 1062 | |
| 1063 | - } |
|
| 1063 | + } |
|
| 1064 | 1064 | |
| 1065 | - // This field has failed validation. |
|
| 1066 | - if( !empty( $field->failed_validation ) ) { |
|
| 1065 | + // This field has failed validation. |
|
| 1066 | + if( !empty( $field->failed_validation ) ) { |
|
| 1067 | 1067 | |
| 1068 | - do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
| 1068 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
| 1069 | 1069 | |
| 1070 | - switch ( $field_type ) { |
|
| 1070 | + switch ( $field_type ) { |
|
| 1071 | 1071 | |
| 1072 | - // Captchas don't need to be re-entered. |
|
| 1073 | - case 'captcha': |
|
| 1072 | + // Captchas don't need to be re-entered. |
|
| 1073 | + case 'captcha': |
|
| 1074 | 1074 | |
| 1075 | - // Post Image fields aren't editable, so we un-fail them. |
|
| 1076 | - case 'post_image': |
|
| 1077 | - $field->failed_validation = false; |
|
| 1078 | - unset( $field->validation_message ); |
|
| 1079 | - break; |
|
| 1075 | + // Post Image fields aren't editable, so we un-fail them. |
|
| 1076 | + case 'post_image': |
|
| 1077 | + $field->failed_validation = false; |
|
| 1078 | + unset( $field->validation_message ); |
|
| 1079 | + break; |
|
| 1080 | 1080 | |
| 1081 | - } |
|
| 1081 | + } |
|
| 1082 | 1082 | |
| 1083 | - // You can't continue inside a switch, so we do it after. |
|
| 1084 | - if( empty( $field->failed_validation ) ) { |
|
| 1085 | - continue; |
|
| 1086 | - } |
|
| 1083 | + // You can't continue inside a switch, so we do it after. |
|
| 1084 | + if( empty( $field->failed_validation ) ) { |
|
| 1085 | + continue; |
|
| 1086 | + } |
|
| 1087 | 1087 | |
| 1088 | - // checks if the No Duplicates option is not validating entry against itself, since |
|
| 1089 | - // we're editing a stored entry, it would also assume it's a duplicate. |
|
| 1090 | - if( !empty( $field->noDuplicates ) ) { |
|
| 1088 | + // checks if the No Duplicates option is not validating entry against itself, since |
|
| 1089 | + // we're editing a stored entry, it would also assume it's a duplicate. |
|
| 1090 | + if( !empty( $field->noDuplicates ) ) { |
|
| 1091 | 1091 | |
| 1092 | - $entry = $this->get_entry(); |
|
| 1092 | + $entry = $this->get_entry(); |
|
| 1093 | 1093 | |
| 1094 | - // If the value of the entry is the same as the stored value |
|
| 1095 | - // Then we can assume it's not a duplicate, it's the same. |
|
| 1096 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1097 | - //if value submitted was not changed, then don't validate |
|
| 1098 | - $field->failed_validation = false; |
|
| 1094 | + // If the value of the entry is the same as the stored value |
|
| 1095 | + // Then we can assume it's not a duplicate, it's the same. |
|
| 1096 | + if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1097 | + //if value submitted was not changed, then don't validate |
|
| 1098 | + $field->failed_validation = false; |
|
| 1099 | 1099 | |
| 1100 | - unset( $field->validation_message ); |
|
| 1100 | + unset( $field->validation_message ); |
|
| 1101 | 1101 | |
| 1102 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1102 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1103 | 1103 | |
| 1104 | - continue; |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1104 | + continue; |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | 1107 | |
| 1108 | - // if here then probably we are facing the validation 'At least one field must be filled out' |
|
| 1109 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1110 | - unset( $field->validation_message ); |
|
| 1111 | - $field->validation_message = false; |
|
| 1112 | - continue; |
|
| 1113 | - } |
|
| 1108 | + // if here then probably we are facing the validation 'At least one field must be filled out' |
|
| 1109 | + if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1110 | + unset( $field->validation_message ); |
|
| 1111 | + $field->validation_message = false; |
|
| 1112 | + continue; |
|
| 1113 | + } |
|
| 1114 | 1114 | |
| 1115 | - $gv_valid = false; |
|
| 1115 | + $gv_valid = false; |
|
| 1116 | 1116 | |
| 1117 | - } |
|
| 1117 | + } |
|
| 1118 | 1118 | |
| 1119 | - } |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | - $validation_results['is_valid'] = $gv_valid; |
|
| 1121 | + $validation_results['is_valid'] = $gv_valid; |
|
| 1122 | 1122 | |
| 1123 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1123 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1124 | 1124 | |
| 1125 | - // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
| 1126 | - $this->form_after_validation = $validation_results['form']; |
|
| 1125 | + // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
| 1126 | + $this->form_after_validation = $validation_results['form']; |
|
| 1127 | 1127 | |
| 1128 | - return $validation_results; |
|
| 1129 | - } |
|
| 1128 | + return $validation_results; |
|
| 1129 | + } |
|
| 1130 | 1130 | |
| 1131 | 1131 | |
| 1132 | - /** |
|
| 1133 | - * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
| 1134 | - * Get the current entry and set it if it's not yet set. |
|
| 1135 | - * @return array Gravity Forms entry array |
|
| 1136 | - */ |
|
| 1137 | - private function get_entry() { |
|
| 1132 | + /** |
|
| 1133 | + * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
| 1134 | + * Get the current entry and set it if it's not yet set. |
|
| 1135 | + * @return array Gravity Forms entry array |
|
| 1136 | + */ |
|
| 1137 | + private function get_entry() { |
|
| 1138 | 1138 | |
| 1139 | - if( empty( $this->entry ) ) { |
|
| 1140 | - // Get the database value of the entry that's being edited |
|
| 1141 | - $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
| 1142 | - } |
|
| 1139 | + if( empty( $this->entry ) ) { |
|
| 1140 | + // Get the database value of the entry that's being edited |
|
| 1141 | + $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
| 1142 | + } |
|
| 1143 | 1143 | |
| 1144 | - return $this->entry; |
|
| 1145 | - } |
|
| 1144 | + return $this->entry; |
|
| 1145 | + } |
|
| 1146 | 1146 | |
| 1147 | 1147 | |
| 1148 | 1148 | |
| 1149 | - // --- Filters |
|
| 1149 | + // --- Filters |
|
| 1150 | 1150 | |
| 1151 | - /** |
|
| 1152 | - * Get the Edit Entry fields as configured in the View |
|
| 1153 | - * |
|
| 1154 | - * @since 1.8 |
|
| 1155 | - * |
|
| 1156 | - * @param int $view_id |
|
| 1157 | - * |
|
| 1158 | - * @return array Array of fields that are configured in the Edit tab in the Admin |
|
| 1159 | - */ |
|
| 1160 | - private function get_configured_edit_fields( $form, $view_id ) { |
|
| 1151 | + /** |
|
| 1152 | + * Get the Edit Entry fields as configured in the View |
|
| 1153 | + * |
|
| 1154 | + * @since 1.8 |
|
| 1155 | + * |
|
| 1156 | + * @param int $view_id |
|
| 1157 | + * |
|
| 1158 | + * @return array Array of fields that are configured in the Edit tab in the Admin |
|
| 1159 | + */ |
|
| 1160 | + private function get_configured_edit_fields( $form, $view_id ) { |
|
| 1161 | 1161 | |
| 1162 | - // Get all fields for form |
|
| 1163 | - $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
| 1162 | + // Get all fields for form |
|
| 1163 | + $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
| 1164 | 1164 | |
| 1165 | - // If edit tab not yet configured, show all fields |
|
| 1166 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1165 | + // If edit tab not yet configured, show all fields |
|
| 1166 | + $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1167 | 1167 | |
| 1168 | - // Show hidden fields as text fields |
|
| 1169 | - $form = $this->fix_hidden_fields( $form ); |
|
| 1168 | + // Show hidden fields as text fields |
|
| 1169 | + $form = $this->fix_hidden_fields( $form ); |
|
| 1170 | 1170 | |
| 1171 | - // Hide fields depending on admin settings |
|
| 1172 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1171 | + // Hide fields depending on admin settings |
|
| 1172 | + $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1173 | 1173 | |
| 1174 | - // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1175 | - $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1174 | + // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1175 | + $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1176 | 1176 | |
| 1177 | - return $fields; |
|
| 1178 | - } |
|
| 1177 | + return $fields; |
|
| 1178 | + } |
|
| 1179 | 1179 | |
| 1180 | 1180 | /** |
| 1181 | 1181 | * @since 1.9.2 |
@@ -1199,364 +1199,364 @@ discard block |
||
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | |
| 1202 | - /** |
|
| 1203 | - * Filter area fields based on specified conditions |
|
| 1204 | - * |
|
| 1205 | - * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
| 1206 | - * @access private |
|
| 1207 | - * @param GF_Field[] $fields |
|
| 1208 | - * @param array $configured_fields |
|
| 1209 | - * @since 1.5 |
|
| 1210 | - * @return array $fields |
|
| 1211 | - */ |
|
| 1212 | - private function filter_fields( $fields, $configured_fields ) { |
|
| 1213 | - |
|
| 1214 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1215 | - return $fields; |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - $edit_fields = array(); |
|
| 1219 | - |
|
| 1220 | - $field_type_blacklist = array( |
|
| 1221 | - 'page', |
|
| 1222 | - ); |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
| 1226 | - * @since 1.9.1 |
|
| 1227 | - * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
| 1228 | - */ |
|
| 1229 | - $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
| 1230 | - |
|
| 1231 | - if( $hide_product_fields ) { |
|
| 1232 | - $field_type_blacklist[] = 'option'; |
|
| 1233 | - $field_type_blacklist[] = 'quantity'; |
|
| 1234 | - $field_type_blacklist[] = 'product'; |
|
| 1235 | - $field_type_blacklist[] = 'total'; |
|
| 1236 | - $field_type_blacklist[] = 'shipping'; |
|
| 1237 | - $field_type_blacklist[] = 'calculation'; |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - // First, remove blacklist |
|
| 1241 | - foreach ( $fields as $key => $field ) { |
|
| 1242 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1243 | - unset( $fields[ $key ] ); |
|
| 1244 | - } |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - // The Edit tab has not been configured, so we return all fields by default. |
|
| 1248 | - if( empty( $configured_fields ) ) { |
|
| 1249 | - return $fields; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - // The edit tab has been configured, so we loop through to configured settings |
|
| 1253 | - foreach ( $configured_fields as $configured_field ) { |
|
| 1254 | - |
|
| 1255 | - /** @var GF_Field $field */ |
|
| 1256 | - foreach ( $fields as $field ) { |
|
| 1257 | - |
|
| 1258 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1259 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1260 | - break; |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - return $edit_fields; |
|
| 1268 | - |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - /** |
|
| 1272 | - * Override GF Form field properties with the ones defined on the View |
|
| 1273 | - * @param GF_Field $field GF Form field object |
|
| 1274 | - * @param array $setting GV field options |
|
| 1275 | - * @since 1.5 |
|
| 1276 | - * @return array |
|
| 1277 | - */ |
|
| 1278 | - private function merge_field_properties( $field, $field_setting ) { |
|
| 1279 | - |
|
| 1280 | - $return_field = $field; |
|
| 1281 | - |
|
| 1282 | - if( empty( $field_setting['show_label'] ) ) { |
|
| 1283 | - $return_field->label = ''; |
|
| 1284 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1285 | - $return_field->label = $field_setting['custom_label']; |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1289 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - /** |
|
| 1293 | - * Normalize page numbers - avoid conflicts with page validation |
|
| 1294 | - * @since 1.6 |
|
| 1295 | - */ |
|
| 1296 | - $return_field->pageNumber = 1; |
|
| 1297 | - |
|
| 1298 | - return $return_field; |
|
| 1299 | - |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
| 1304 | - * |
|
| 1305 | - * @since 1.9.1 |
|
| 1306 | - * |
|
| 1307 | - * @param array|GF_Field[] $fields Gravity Forms form fields |
|
| 1308 | - * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1309 | - * @param array $form GF Form array |
|
| 1310 | - * @param int $view_id View ID |
|
| 1311 | - * |
|
| 1312 | - * @return array Possibly modified form array |
|
| 1313 | - */ |
|
| 1314 | - function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * @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 |
|
| 1318 | - * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1319 | - * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1320 | - * @since 1.9.1 |
|
| 1321 | - * @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. |
|
| 1322 | - * @param array $form GF Form array |
|
| 1323 | - * @param int $view_id View ID |
|
| 1324 | - */ |
|
| 1325 | - $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1326 | - |
|
| 1327 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1328 | - return $fields; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - foreach( $fields as &$field ) { |
|
| 1332 | - $field->adminOnly = false; |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - return $fields; |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - // --- Conditional Logic |
|
| 1339 | - |
|
| 1340 | - /** |
|
| 1341 | - * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
| 1342 | - * |
|
| 1343 | - * @since 1.9 |
|
| 1344 | - * |
|
| 1345 | - * @param array $form Gravity Forms form |
|
| 1346 | - * @return array Modified form, if not using Conditional Logic |
|
| 1347 | - */ |
|
| 1348 | - function filter_conditional_logic( $form ) { |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
| 1352 | - * @since 1.9 |
|
| 1353 | - * @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 |
|
| 1354 | - * @param array $form Gravity Forms form |
|
| 1355 | - */ |
|
| 1356 | - $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
| 1357 | - |
|
| 1358 | - if( $use_conditional_logic ) { |
|
| 1359 | - return $form; |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - foreach( $form['fields'] as &$field ) { |
|
| 1363 | - /* @var GF_Field $field */ |
|
| 1364 | - $field->conditionalLogic = null; |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - unset( $form['button']['conditionalLogic'] ); |
|
| 1368 | - |
|
| 1369 | - return $form; |
|
| 1370 | - |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
| 1375 | - * |
|
| 1376 | - * @since 1.9 |
|
| 1377 | - * |
|
| 1378 | - * @param $has_conditional_logic |
|
| 1379 | - * @param $form |
|
| 1380 | - * @return mixed|void |
|
| 1381 | - */ |
|
| 1382 | - function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
| 1383 | - |
|
| 1384 | - if( ! $this->is_edit_entry() ) { |
|
| 1385 | - return $has_conditional_logic; |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
| 1389 | - |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - |
|
| 1393 | - // --- User checks and nonces |
|
| 1394 | - |
|
| 1395 | - /** |
|
| 1396 | - * Check if the user can edit the entry |
|
| 1397 | - * |
|
| 1398 | - * - Is the nonce valid? |
|
| 1399 | - * - Does the user have the right caps for the entry |
|
| 1400 | - * - Is the entry in the trash? |
|
| 1401 | - * |
|
| 1402 | - * @todo Move to GVCommon |
|
| 1403 | - * |
|
| 1404 | - * @param boolean $echo Show error messages in the form? |
|
| 1405 | - * @return boolean True: can edit form. False: nope. |
|
| 1406 | - */ |
|
| 1407 | - function user_can_edit_entry( $echo = false ) { |
|
| 1408 | - |
|
| 1409 | - $error = NULL; |
|
| 1410 | - |
|
| 1411 | - /** |
|
| 1412 | - * 1. Permalinks are turned off |
|
| 1413 | - * 2. There are two entries embedded using oEmbed |
|
| 1414 | - * 3. One of the entries has just been saved |
|
| 1415 | - */ |
|
| 1416 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1417 | - |
|
| 1418 | - $error = true; |
|
| 1419 | - |
|
| 1420 | - } |
|
| 1202 | + /** |
|
| 1203 | + * Filter area fields based on specified conditions |
|
| 1204 | + * |
|
| 1205 | + * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
| 1206 | + * @access private |
|
| 1207 | + * @param GF_Field[] $fields |
|
| 1208 | + * @param array $configured_fields |
|
| 1209 | + * @since 1.5 |
|
| 1210 | + * @return array $fields |
|
| 1211 | + */ |
|
| 1212 | + private function filter_fields( $fields, $configured_fields ) { |
|
| 1213 | + |
|
| 1214 | + if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1215 | + return $fields; |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + $edit_fields = array(); |
|
| 1219 | + |
|
| 1220 | + $field_type_blacklist = array( |
|
| 1221 | + 'page', |
|
| 1222 | + ); |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
| 1226 | + * @since 1.9.1 |
|
| 1227 | + * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
| 1228 | + */ |
|
| 1229 | + $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
| 1230 | + |
|
| 1231 | + if( $hide_product_fields ) { |
|
| 1232 | + $field_type_blacklist[] = 'option'; |
|
| 1233 | + $field_type_blacklist[] = 'quantity'; |
|
| 1234 | + $field_type_blacklist[] = 'product'; |
|
| 1235 | + $field_type_blacklist[] = 'total'; |
|
| 1236 | + $field_type_blacklist[] = 'shipping'; |
|
| 1237 | + $field_type_blacklist[] = 'calculation'; |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + // First, remove blacklist |
|
| 1241 | + foreach ( $fields as $key => $field ) { |
|
| 1242 | + if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1243 | + unset( $fields[ $key ] ); |
|
| 1244 | + } |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + // The Edit tab has not been configured, so we return all fields by default. |
|
| 1248 | + if( empty( $configured_fields ) ) { |
|
| 1249 | + return $fields; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + // The edit tab has been configured, so we loop through to configured settings |
|
| 1253 | + foreach ( $configured_fields as $configured_field ) { |
|
| 1254 | + |
|
| 1255 | + /** @var GF_Field $field */ |
|
| 1256 | + foreach ( $fields as $field ) { |
|
| 1257 | + |
|
| 1258 | + if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1259 | + $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1260 | + break; |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + return $edit_fields; |
|
| 1268 | + |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + /** |
|
| 1272 | + * Override GF Form field properties with the ones defined on the View |
|
| 1273 | + * @param GF_Field $field GF Form field object |
|
| 1274 | + * @param array $setting GV field options |
|
| 1275 | + * @since 1.5 |
|
| 1276 | + * @return array |
|
| 1277 | + */ |
|
| 1278 | + private function merge_field_properties( $field, $field_setting ) { |
|
| 1279 | + |
|
| 1280 | + $return_field = $field; |
|
| 1281 | + |
|
| 1282 | + if( empty( $field_setting['show_label'] ) ) { |
|
| 1283 | + $return_field->label = ''; |
|
| 1284 | + } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1285 | + $return_field->label = $field_setting['custom_label']; |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1289 | + $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + /** |
|
| 1293 | + * Normalize page numbers - avoid conflicts with page validation |
|
| 1294 | + * @since 1.6 |
|
| 1295 | + */ |
|
| 1296 | + $return_field->pageNumber = 1; |
|
| 1297 | + |
|
| 1298 | + return $return_field; |
|
| 1299 | + |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
| 1304 | + * |
|
| 1305 | + * @since 1.9.1 |
|
| 1306 | + * |
|
| 1307 | + * @param array|GF_Field[] $fields Gravity Forms form fields |
|
| 1308 | + * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1309 | + * @param array $form GF Form array |
|
| 1310 | + * @param int $view_id View ID |
|
| 1311 | + * |
|
| 1312 | + * @return array Possibly modified form array |
|
| 1313 | + */ |
|
| 1314 | + function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * @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 |
|
| 1318 | + * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1319 | + * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1320 | + * @since 1.9.1 |
|
| 1321 | + * @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. |
|
| 1322 | + * @param array $form GF Form array |
|
| 1323 | + * @param int $view_id View ID |
|
| 1324 | + */ |
|
| 1325 | + $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1326 | + |
|
| 1327 | + if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1328 | + return $fields; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + foreach( $fields as &$field ) { |
|
| 1332 | + $field->adminOnly = false; |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + return $fields; |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + // --- Conditional Logic |
|
| 1339 | + |
|
| 1340 | + /** |
|
| 1341 | + * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
| 1342 | + * |
|
| 1343 | + * @since 1.9 |
|
| 1344 | + * |
|
| 1345 | + * @param array $form Gravity Forms form |
|
| 1346 | + * @return array Modified form, if not using Conditional Logic |
|
| 1347 | + */ |
|
| 1348 | + function filter_conditional_logic( $form ) { |
|
| 1349 | + |
|
| 1350 | + /** |
|
| 1351 | + * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
| 1352 | + * @since 1.9 |
|
| 1353 | + * @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 |
|
| 1354 | + * @param array $form Gravity Forms form |
|
| 1355 | + */ |
|
| 1356 | + $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
| 1357 | + |
|
| 1358 | + if( $use_conditional_logic ) { |
|
| 1359 | + return $form; |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + foreach( $form['fields'] as &$field ) { |
|
| 1363 | + /* @var GF_Field $field */ |
|
| 1364 | + $field->conditionalLogic = null; |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + unset( $form['button']['conditionalLogic'] ); |
|
| 1368 | + |
|
| 1369 | + return $form; |
|
| 1370 | + |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
| 1375 | + * |
|
| 1376 | + * @since 1.9 |
|
| 1377 | + * |
|
| 1378 | + * @param $has_conditional_logic |
|
| 1379 | + * @param $form |
|
| 1380 | + * @return mixed|void |
|
| 1381 | + */ |
|
| 1382 | + function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
| 1383 | + |
|
| 1384 | + if( ! $this->is_edit_entry() ) { |
|
| 1385 | + return $has_conditional_logic; |
|
| 1386 | + } |
|
| 1421 | 1387 | |
| 1422 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1388 | + return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
| 1423 | 1389 | |
| 1424 | - $error = true; |
|
| 1390 | + } |
|
| 1425 | 1391 | |
| 1426 | - } elseif( ! $this->verify_nonce() ) { |
|
| 1427 | 1392 | |
| 1428 | - /** |
|
| 1429 | - * If the Entry is embedded, there may be two entries on the same page. |
|
| 1430 | - * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
| 1431 | - */ |
|
| 1432 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1433 | - $error = true; |
|
| 1434 | - } else { |
|
| 1435 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1436 | - } |
|
| 1393 | + // --- User checks and nonces |
|
| 1437 | 1394 | |
| 1438 | - } |
|
| 1395 | + /** |
|
| 1396 | + * Check if the user can edit the entry |
|
| 1397 | + * |
|
| 1398 | + * - Is the nonce valid? |
|
| 1399 | + * - Does the user have the right caps for the entry |
|
| 1400 | + * - Is the entry in the trash? |
|
| 1401 | + * |
|
| 1402 | + * @todo Move to GVCommon |
|
| 1403 | + * |
|
| 1404 | + * @param boolean $echo Show error messages in the form? |
|
| 1405 | + * @return boolean True: can edit form. False: nope. |
|
| 1406 | + */ |
|
| 1407 | + function user_can_edit_entry( $echo = false ) { |
|
| 1439 | 1408 | |
| 1440 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1441 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1442 | - } |
|
| 1409 | + $error = NULL; |
|
| 1443 | 1410 | |
| 1444 | - if( $this->entry['status'] === 'trash' ) { |
|
| 1445 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1446 | - } |
|
| 1411 | + /** |
|
| 1412 | + * 1. Permalinks are turned off |
|
| 1413 | + * 2. There are two entries embedded using oEmbed |
|
| 1414 | + * 3. One of the entries has just been saved |
|
| 1415 | + */ |
|
| 1416 | + if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1447 | 1417 | |
| 1448 | - // No errors; everything's fine here! |
|
| 1449 | - if( empty( $error ) ) { |
|
| 1450 | - return true; |
|
| 1451 | - } |
|
| 1418 | + $error = true; |
|
| 1452 | 1419 | |
| 1453 | - if( $echo && $error !== true ) { |
|
| 1420 | + } |
|
| 1454 | 1421 | |
| 1455 | - $error = esc_html( $error ); |
|
| 1422 | + if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1456 | 1423 | |
| 1457 | - /** |
|
| 1458 | - * @since 1.9 |
|
| 1459 | - */ |
|
| 1460 | - if ( ! empty( $this->entry ) ) { |
|
| 1461 | - $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;" ) ); |
|
| 1462 | - } |
|
| 1424 | + $error = true; |
|
| 1463 | 1425 | |
| 1464 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1465 | - } |
|
| 1426 | + } elseif( ! $this->verify_nonce() ) { |
|
| 1466 | 1427 | |
| 1467 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1428 | + /** |
|
| 1429 | + * If the Entry is embedded, there may be two entries on the same page. |
|
| 1430 | + * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
| 1431 | + */ |
|
| 1432 | + if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1433 | + $error = true; |
|
| 1434 | + } else { |
|
| 1435 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1436 | + } |
|
| 1468 | 1437 | |
| 1469 | - return false; |
|
| 1470 | - } |
|
| 1438 | + } |
|
| 1471 | 1439 | |
| 1440 | + if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1441 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1442 | + } |
|
| 1472 | 1443 | |
| 1473 | - /** |
|
| 1474 | - * Check whether a field is editable by the current user, and optionally display an error message |
|
| 1475 | - * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
| 1476 | - * @param array $field Field or field settings array |
|
| 1477 | - * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
| 1478 | - * @return boolean True: user can edit the current field; False: nope, they can't. |
|
| 1479 | - */ |
|
| 1480 | - private function user_can_edit_field( $field, $echo = false ) { |
|
| 1444 | + if( $this->entry['status'] === 'trash' ) { |
|
| 1445 | + $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1446 | + } |
|
| 1481 | 1447 | |
| 1482 | - $error = NULL; |
|
| 1448 | + // No errors; everything's fine here! |
|
| 1449 | + if( empty( $error ) ) { |
|
| 1450 | + return true; |
|
| 1451 | + } |
|
| 1483 | 1452 | |
| 1484 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1485 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1486 | - } |
|
| 1453 | + if( $echo && $error !== true ) { |
|
| 1487 | 1454 | |
| 1488 | - // No errors; everything's fine here! |
|
| 1489 | - if( empty( $error ) ) { |
|
| 1490 | - return true; |
|
| 1491 | - } |
|
| 1455 | + $error = esc_html( $error ); |
|
| 1492 | 1456 | |
| 1493 | - if( $echo ) { |
|
| 1494 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1457 | + /** |
|
| 1458 | + * @since 1.9 |
|
| 1459 | + */ |
|
| 1460 | + if ( ! empty( $this->entry ) ) { |
|
| 1461 | + $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;" ) ); |
|
| 1462 | + } |
|
| 1498 | 1463 | |
| 1499 | - return false; |
|
| 1464 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1465 | + } |
|
| 1500 | 1466 | |
| 1501 | - } |
|
| 1467 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1502 | 1468 | |
| 1469 | + return false; |
|
| 1470 | + } |
|
| 1503 | 1471 | |
| 1504 | - /** |
|
| 1505 | - * checks if user has permissions to edit a specific field |
|
| 1506 | - * |
|
| 1507 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
| 1508 | - * |
|
| 1509 | - * @param [type] $field [description] |
|
| 1510 | - * @return bool |
|
| 1511 | - */ |
|
| 1512 | - private function check_user_cap_edit_field( $field ) { |
|
| 1513 | 1472 | |
| 1514 | - // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
| 1515 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1516 | - return true; |
|
| 1517 | - } |
|
| 1473 | + /** |
|
| 1474 | + * Check whether a field is editable by the current user, and optionally display an error message |
|
| 1475 | + * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
| 1476 | + * @param array $field Field or field settings array |
|
| 1477 | + * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
| 1478 | + * @return boolean True: user can edit the current field; False: nope, they can't. |
|
| 1479 | + */ |
|
| 1480 | + private function user_can_edit_field( $field, $echo = false ) { |
|
| 1518 | 1481 | |
| 1519 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1482 | + $error = NULL; |
|
| 1520 | 1483 | |
| 1521 | - // If the field has custom editing capaibilities set, check those |
|
| 1522 | - if( $field_cap ) { |
|
| 1523 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - return false; |
|
| 1527 | - } |
|
| 1484 | + if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1485 | + $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1486 | + } |
|
| 1528 | 1487 | |
| 1488 | + // No errors; everything's fine here! |
|
| 1489 | + if( empty( $error ) ) { |
|
| 1490 | + return true; |
|
| 1491 | + } |
|
| 1529 | 1492 | |
| 1530 | - /** |
|
| 1531 | - * Is the current nonce valid for editing the entry? |
|
| 1532 | - * @return boolean |
|
| 1533 | - */ |
|
| 1534 | - public function verify_nonce() { |
|
| 1493 | + if( $echo ) { |
|
| 1494 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1495 | + } |
|
| 1535 | 1496 | |
| 1536 | - // Verify form submitted for editing single |
|
| 1537 | - if( $this->is_edit_entry_submission() ) { |
|
| 1538 | - $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
| 1539 | - } |
|
| 1497 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1540 | 1498 | |
| 1541 | - // Verify |
|
| 1542 | - else if( ! $this->is_edit_entry() ) { |
|
| 1543 | - $valid = false; |
|
| 1544 | - } |
|
| 1499 | + return false; |
|
| 1545 | 1500 | |
| 1546 | - else { |
|
| 1547 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 1548 | - } |
|
| 1501 | + } |
|
| 1549 | 1502 | |
| 1550 | - /** |
|
| 1551 | - * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
| 1552 | - * @since 1.13 |
|
| 1553 | - * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
| 1554 | - * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
| 1555 | - */ |
|
| 1556 | - $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
| 1557 | 1503 | |
| 1558 | - return $valid; |
|
| 1559 | - } |
|
| 1504 | + /** |
|
| 1505 | + * checks if user has permissions to edit a specific field |
|
| 1506 | + * |
|
| 1507 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
| 1508 | + * |
|
| 1509 | + * @param [type] $field [description] |
|
| 1510 | + * @return bool |
|
| 1511 | + */ |
|
| 1512 | + private function check_user_cap_edit_field( $field ) { |
|
| 1513 | + |
|
| 1514 | + // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
| 1515 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1516 | + return true; |
|
| 1517 | + } |
|
| 1518 | + |
|
| 1519 | + $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1520 | + |
|
| 1521 | + // If the field has custom editing capaibilities set, check those |
|
| 1522 | + if( $field_cap ) { |
|
| 1523 | + return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + return false; |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * Is the current nonce valid for editing the entry? |
|
| 1532 | + * @return boolean |
|
| 1533 | + */ |
|
| 1534 | + public function verify_nonce() { |
|
| 1535 | + |
|
| 1536 | + // Verify form submitted for editing single |
|
| 1537 | + if( $this->is_edit_entry_submission() ) { |
|
| 1538 | + $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
| 1539 | + } |
|
| 1540 | + |
|
| 1541 | + // Verify |
|
| 1542 | + else if( ! $this->is_edit_entry() ) { |
|
| 1543 | + $valid = false; |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + else { |
|
| 1547 | + $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 1548 | + } |
|
| 1549 | + |
|
| 1550 | + /** |
|
| 1551 | + * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
| 1552 | + * @since 1.13 |
|
| 1553 | + * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
| 1554 | + * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
| 1555 | + */ |
|
| 1556 | + $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
| 1557 | + |
|
| 1558 | + return $valid; |
|
| 1559 | + } |
|
| 1560 | 1560 | |
| 1561 | 1561 | |
| 1562 | 1562 | |
@@ -91,16 +91,16 @@ discard block |
||
| 91 | 91 | function load() { |
| 92 | 92 | |
| 93 | 93 | /** @define "GRAVITYVIEW_DIR" "../../../" */ |
| 94 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 94 | + include_once( GRAVITYVIEW_DIR . 'includes/class-admin-approve-entries.php' ); |
|
| 95 | 95 | |
| 96 | 96 | // Don't display an embedded form when editing an entry |
| 97 | 97 | add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
| 98 | 98 | add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
| 99 | 99 | |
| 100 | 100 | // Stop Gravity Forms processing what is ours! |
| 101 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 101 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form' ), 8 ); |
|
| 102 | 102 | |
| 103 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 103 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry' ) ); |
|
| 104 | 104 | |
| 105 | 105 | add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
| 106 | 106 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
| 112 | 112 | |
| 113 | 113 | // Add fields expected by GFFormDisplay::validate() |
| 114 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 114 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation' ) ); |
|
| 115 | 115 | |
| 116 | 116 | } |
| 117 | 117 | |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @return void |
| 127 | 127 | */ |
| 128 | 128 | function prevent_render_form() { |
| 129 | - if( $this->is_edit_entry() ) { |
|
| 130 | - if( 'wp_head' === current_filter() ) { |
|
| 129 | + if ( $this->is_edit_entry() ) { |
|
| 130 | + if ( 'wp_head' === current_filter() ) { |
|
| 131 | 131 | add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
| 132 | 132 | } else { |
| 133 | 133 | remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | function prevent_maybe_process_form() { |
| 144 | 144 | |
| 145 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 145 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 146 | 146 | |
| 147 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 148 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 147 | + if ( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 148 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form' ), 9 ); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | $gf_page = ( 'entry' === RGForms::get( 'view' ) ); |
| 159 | 159 | |
| 160 | - return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); |
|
| 160 | + return ( $gf_page && isset( $_GET[ 'edit' ] ) || RGForms::post( 'action' ) === 'update' ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @return boolean |
| 167 | 167 | */ |
| 168 | 168 | public function is_edit_entry_submission() { |
| 169 | - return !empty( $_POST[ self::$nonce_field ] ); |
|
| 169 | + return ! empty( $_POST[ self::$nonce_field ] ); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | |
| 179 | 179 | $entries = $gravityview_view->getEntries(); |
| 180 | - $this->entry = $entries[0]; |
|
| 180 | + $this->entry = $entries[ 0 ]; |
|
| 181 | 181 | |
| 182 | 182 | |
| 183 | 183 | $this->form = $gravityview_view->getForm(); |
| 184 | 184 | $this->form_id = $gravityview_view->getFormId(); |
| 185 | 185 | $this->view_id = $gravityview_view->getViewId(); |
| 186 | 186 | |
| 187 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 187 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry[ 'id' ] ); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
@@ -204,12 +204,12 @@ discard block |
||
| 204 | 204 | $this->setup_vars(); |
| 205 | 205 | |
| 206 | 206 | // Multiple Views embedded, don't proceed if nonce fails |
| 207 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 207 | + if ( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ) ) { |
|
| 208 | 208 | return; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // Sorry, you're not allowed here. |
| 212 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
| 212 | + if ( false === $this->user_can_edit_entry( true ) ) { |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -229,9 +229,9 @@ discard block |
||
| 229 | 229 | function print_scripts() { |
| 230 | 230 | $gravityview_view = GravityView_View::getInstance(); |
| 231 | 231 | |
| 232 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 232 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url() . '/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 233 | 233 | |
| 234 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 234 | + GFFormDisplay::enqueue_form_scripts( $gravityview_view->getForm(), false ); |
|
| 235 | 235 | |
| 236 | 236 | // Sack is required for images |
| 237 | 237 | wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
@@ -243,32 +243,32 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | function process_save() { |
| 245 | 245 | |
| 246 | - if( empty( $_POST ) ) { |
|
| 246 | + if ( empty( $_POST ) ) { |
|
| 247 | 247 | return; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | // Make sure the entry, view, and form IDs are all correct |
| 251 | 251 | $valid = $this->verify_nonce(); |
| 252 | 252 | |
| 253 | - if( !$valid ) { |
|
| 254 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 253 | + if ( ! $valid ) { |
|
| 254 | + do_action( 'gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 255 | 255 | return; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 259 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 258 | + if ( $this->entry[ 'id' ] !== $_POST[ 'lid' ] ) { |
|
| 259 | + do_action( 'gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 263 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 264 | 264 | |
| 265 | 265 | $this->process_save_process_files( $this->form_id ); |
| 266 | 266 | |
| 267 | 267 | $this->validate(); |
| 268 | 268 | |
| 269 | - if( $this->is_valid ) { |
|
| 269 | + if ( $this->is_valid ) { |
|
| 270 | 270 | |
| 271 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
| 271 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | 274 | * @hack This step is needed to unset the adminOnly from form fields |
@@ -278,12 +278,12 @@ discard block |
||
| 278 | 278 | /** |
| 279 | 279 | * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
| 280 | 280 | */ |
| 281 | - unset( $_GET['page'] ); |
|
| 281 | + unset( $_GET[ 'page' ] ); |
|
| 282 | 282 | |
| 283 | 283 | GFFormsModel::save_lead( $form, $this->entry ); |
| 284 | 284 | |
| 285 | 285 | // If there's a post associated with the entry, process post fields |
| 286 | - if( !empty( $this->entry['post_id'] ) ) { |
|
| 286 | + if ( ! empty( $this->entry[ 'post_id' ] ) ) { |
|
| 287 | 287 | $this->maybe_update_post_fields( $form ); |
| 288 | 288 | } |
| 289 | 289 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @param array $form Gravity Forms form array |
| 296 | 296 | * @param string $entry_id Numeric ID of the entry that was updated |
| 297 | 297 | */ |
| 298 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 298 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry[ 'id' ] ); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | } // process_save |
@@ -329,11 +329,11 @@ discard block |
||
| 329 | 329 | * @return mixed |
| 330 | 330 | */ |
| 331 | 331 | public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
| 332 | - if( ! $this->is_edit_entry() ) { |
|
| 332 | + if ( ! $this->is_edit_entry() ) { |
|
| 333 | 333 | return $plupload_init; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - $plupload_init['gf_vars']['max_files'] = 0; |
|
| 336 | + $plupload_init[ 'gf_vars' ][ 'max_files' ] = 0; |
|
| 337 | 337 | |
| 338 | 338 | return $plupload_init; |
| 339 | 339 | } |
@@ -346,13 +346,13 @@ discard block |
||
| 346 | 346 | private function form_prepare_for_save() { |
| 347 | 347 | $form = $this->form; |
| 348 | 348 | |
| 349 | - foreach( $form['fields'] as &$field ) { |
|
| 349 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 350 | 350 | |
| 351 | 351 | $field->adminOnly = false; |
| 352 | 352 | |
| 353 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 354 | - foreach( $field->inputs as $key => $input ) { |
|
| 355 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 353 | + if ( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 354 | + foreach ( $field->inputs as $key => $input ) { |
|
| 355 | + $field->inputs[ $key ][ 'id' ] = (string)$input[ 'id' ]; |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | } |
@@ -370,11 +370,11 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | function maybe_update_post_fields( $form ) { |
| 372 | 372 | |
| 373 | - $post_id = $this->entry['post_id']; |
|
| 373 | + $post_id = $this->entry[ 'post_id' ]; |
|
| 374 | 374 | |
| 375 | 375 | // Security check |
| 376 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 377 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 376 | + if ( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 377 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id ); |
|
| 378 | 378 | return; |
| 379 | 379 | } |
| 380 | 380 | |
@@ -388,11 +388,11 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | $field = RGFormsModel::get_field( $form, $field_id ); |
| 390 | 390 | |
| 391 | - if( class_exists('GF_Fields') ) { |
|
| 391 | + if ( class_exists( 'GF_Fields' ) ) { |
|
| 392 | 392 | $field = GF_Fields::create( $field ); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 395 | + if ( GFCommon::is_post_field( $field ) ) { |
|
| 396 | 396 | |
| 397 | 397 | // Get the value of the field, including $_POSTed value |
| 398 | 398 | $value = RGFormsModel::get_field_value( $field ); |
@@ -400,12 +400,12 @@ discard block |
||
| 400 | 400 | // Convert the field object in 1.9 to an array for backward compatibility |
| 401 | 401 | $field_array = GVCommon::get_field_array( $field ); |
| 402 | 402 | |
| 403 | - switch( $field_array['type'] ) { |
|
| 403 | + switch ( $field_array[ 'type' ] ) { |
|
| 404 | 404 | |
| 405 | 405 | case 'post_title': |
| 406 | 406 | case 'post_content': |
| 407 | 407 | case 'post_excerpt': |
| 408 | - $updated_post->{$field_array['type']} = $value; |
|
| 408 | + $updated_post->{$field_array[ 'type' ]} = $value; |
|
| 409 | 409 | break; |
| 410 | 410 | case 'post_tags': |
| 411 | 411 | wp_set_post_tags( $post_id, $value, false ); |
@@ -421,24 +421,24 @@ discard block |
||
| 421 | 421 | $field = GFCommon::add_categories_as_choices( $field, '' ); |
| 422 | 422 | |
| 423 | 423 | // if post_category is type checkbox, then value is an array of inputs |
| 424 | - if( isset( $value[ strval( $field_id ) ] ) ) { |
|
| 425 | - foreach( $value as $input_id => $val ) { |
|
| 424 | + if ( isset( $value[ strval( $field_id ) ] ) ) { |
|
| 425 | + foreach ( $value as $input_id => $val ) { |
|
| 426 | 426 | $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
| 427 | - $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); |
|
| 427 | + $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry[ 'id' ] ); |
|
| 428 | 428 | } |
| 429 | 429 | } else { |
| 430 | 430 | $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
| 431 | - $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); |
|
| 431 | + $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry[ 'id' ] ); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | break; |
| 435 | 435 | case 'post_custom_field': |
| 436 | 436 | |
| 437 | 437 | $input_type = RGFormsModel::get_input_type( $field ); |
| 438 | - $custom_field_name = $field_array['postCustomFieldName']; |
|
| 438 | + $custom_field_name = $field_array[ 'postCustomFieldName' ]; |
|
| 439 | 439 | |
| 440 | 440 | // Only certain custom field types are supported |
| 441 | - if( !in_array( $input_type, array( 'list', 'fileupload' ) ) ) { |
|
| 441 | + if ( ! in_array( $input_type, array( 'list', 'fileupload' ) ) ) { |
|
| 442 | 442 | update_post_meta( $post_id, $custom_field_name, $value ); |
| 443 | 443 | } |
| 444 | 444 | |
@@ -452,12 +452,12 @@ discard block |
||
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | //ignore fields that have not changed |
| 455 | - if ( $value === rgget( (string) $field_id, $this->entry ) ) { |
|
| 455 | + if ( $value === rgget( (string)$field_id, $this->entry ) ) { |
|
| 456 | 456 | continue; |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // update entry |
| 460 | - if( 'post_category' !== $field->type ) { |
|
| 460 | + if ( 'post_category' !== $field->type ) { |
|
| 461 | 461 | $this->entry[ strval( $field_id ) ] = $value; |
| 462 | 462 | } |
| 463 | 463 | |
@@ -467,24 +467,24 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - if( $update_entry ) { |
|
| 470 | + if ( $update_entry ) { |
|
| 471 | 471 | |
| 472 | 472 | $return_entry = GFAPI::update_entry( $this->entry ); |
| 473 | 473 | |
| 474 | - if( is_wp_error( $return_entry ) ) { |
|
| 474 | + if ( is_wp_error( $return_entry ) ) { |
|
| 475 | 475 | do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
| 476 | 476 | } else { |
| 477 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 477 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded' ); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | $return_post = wp_update_post( $updated_post, true ); |
| 483 | 483 | |
| 484 | - if( is_wp_error( $return_post ) ) { |
|
| 484 | + if ( is_wp_error( $return_post ) ) { |
|
| 485 | 485 | do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
| 486 | 486 | } else { |
| 487 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded' ); |
|
| 487 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded' ); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | } |
@@ -500,18 +500,18 @@ discard block |
||
| 500 | 500 | */ |
| 501 | 501 | function after_update() { |
| 502 | 502 | |
| 503 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
| 504 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 503 | + do_action( 'gform_after_update_entry', $this->form, $this->entry[ 'id' ] ); |
|
| 504 | + do_action( "gform_after_update_entry_{$this->form[ 'id' ]}", $this->form, $this->entry[ 'id' ] ); |
|
| 505 | 505 | |
| 506 | 506 | // Re-define the entry now that we've updated it. |
| 507 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 507 | + $entry = RGFormsModel::get_lead( $this->entry[ 'id' ] ); |
|
| 508 | 508 | |
| 509 | 509 | $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
| 510 | 510 | |
| 511 | 511 | // We need to clear the cache because Gravity Forms caches the field values, which |
| 512 | 512 | // we have just updated. |
| 513 | - foreach ($this->form['fields'] as $key => $field) { |
|
| 514 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 513 | + foreach ( $this->form[ 'fields' ] as $key => $field ) { |
|
| 514 | + GFFormsModel::refresh_lead_field_value( $entry[ 'id' ], $field->id ); |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | $this->entry = $entry; |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | |
| 532 | 532 | <div class="gv-edit-entry-wrapper"><?php |
| 533 | 533 | |
| 534 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 534 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/inline-javascript.php', $this ); |
|
| 535 | 535 | |
| 536 | 536 | /** |
| 537 | 537 | * Fixes weird wpautop() issue |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | * @param string $edit_entry_title Modify the "Edit Entry" title |
| 548 | 548 | * @param GravityView_Edit_Entry_Render $this This object |
| 549 | 549 | */ |
| 550 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 550 | + $edit_entry_title = apply_filters( 'gravityview_edit_entry_title', __( 'Edit Entry', 'gravityview' ), $this ); |
|
| 551 | 551 | |
| 552 | 552 | echo esc_attr( $edit_entry_title ); |
| 553 | 553 | ?></span> |
@@ -556,18 +556,18 @@ discard block |
||
| 556 | 556 | <?php |
| 557 | 557 | |
| 558 | 558 | // Display the success message |
| 559 | - if( rgpost('action') === 'update' ) { |
|
| 559 | + if ( rgpost( 'action' ) === 'update' ) { |
|
| 560 | 560 | |
| 561 | - if( ! $this->is_valid ){ |
|
| 561 | + if ( ! $this->is_valid ) { |
|
| 562 | 562 | |
| 563 | 563 | // Keeping this compatible with Gravity Forms. |
| 564 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 565 | - $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 564 | + $validation_message = "<div class='validation_error'>" . __( 'There was a problem with your submission.', 'gravityview' ) . " " . __( 'Errors have been highlighted below.', 'gravityview' ) . "</div>"; |
|
| 565 | + $message = apply_filters( "gform_validation_message_{$this->form[ 'id' ]}", apply_filters( "gform_validation_message", $validation_message, $this->form ), $this->form ); |
|
| 566 | 566 | |
| 567 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 567 | + echo GVCommon::generate_notice( $message, 'gv-error' ); |
|
| 568 | 568 | |
| 569 | 569 | } else { |
| 570 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 570 | + $entry_updated_message = sprintf( esc_attr__( 'Entry Updated. %sReturn to Entry%s', 'gravityview' ), '<a href="' . $back_link . '">', '</a>' ); |
|
| 571 | 571 | |
| 572 | 572 | /** |
| 573 | 573 | * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | * @param array $entry Gravity Forms entry array |
| 578 | 578 | * @param string $back_link URL to return to the original entry. @since 1.6 |
| 579 | 579 | */ |
| 580 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 580 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry, $back_link ); |
|
| 581 | 581 | |
| 582 | 582 | echo GVCommon::generate_notice( $message ); |
| 583 | 583 | } |
@@ -634,13 +634,13 @@ discard block |
||
| 634 | 634 | */ |
| 635 | 635 | private function render_edit_form() { |
| 636 | 636 | |
| 637 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 638 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 637 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000, 3 ); |
|
| 638 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 639 | 639 | add_filter( 'gform_disable_view_counter', '__return_true' ); |
| 640 | 640 | add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
| 641 | 641 | |
| 642 | 642 | // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
| 643 | - unset( $_GET['page'] ); |
|
| 643 | + unset( $_GET[ 'page' ] ); |
|
| 644 | 644 | |
| 645 | 645 | // TODO: Make sure validation isn't handled by GF |
| 646 | 646 | // TODO: Include CSS for file upload fields |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | // TODO: Product fields are not editable |
| 649 | 649 | // TODO: Check Updated and Error messages |
| 650 | 650 | |
| 651 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 651 | + $html = GFFormDisplay::get_form( $this->form[ 'id' ], false, false, true, $this->entry ); |
|
| 652 | 652 | |
| 653 | 653 | remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
| 654 | 654 | remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
@@ -664,7 +664,7 @@ discard block |
||
| 664 | 664 | * @return string |
| 665 | 665 | */ |
| 666 | 666 | public function render_form_buttons() { |
| 667 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 667 | + return gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/form-buttons.php', $this ); |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | |
@@ -684,17 +684,17 @@ discard block |
||
| 684 | 684 | public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
| 685 | 685 | |
| 686 | 686 | // In case we have validated the form, use it to inject the validation results into the form render |
| 687 | - if( isset( $this->form_after_validation ) ) { |
|
| 687 | + if ( isset( $this->form_after_validation ) ) { |
|
| 688 | 688 | $form = $this->form_after_validation; |
| 689 | 689 | } else { |
| 690 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 690 | + $form[ 'fields' ] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | $form = $this->filter_conditional_logic( $form ); |
| 694 | 694 | |
| 695 | 695 | // for now we don't support Save and Continue feature. |
| 696 | - if( ! self::$supports_save_and_continue ) { |
|
| 697 | - unset( $form['save'] ); |
|
| 696 | + if ( ! self::$supports_save_and_continue ) { |
|
| 697 | + unset( $form[ 'save' ] ); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | return $form; |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | |
| 718 | 718 | // If the form has been submitted, then we don't need to pre-fill the values, |
| 719 | 719 | // Except for fileupload type - run always!! |
| 720 | - if( |
|
| 720 | + if ( |
|
| 721 | 721 | $this->is_edit_entry_submission() && 'fileupload' !== $field->type |
| 722 | 722 | || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
| 723 | 723 | ) { |
@@ -725,8 +725,8 @@ discard block |
||
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | // Turn on Admin-style display for file upload fields only |
| 728 | - if( 'fileupload' === $field->type ) { |
|
| 729 | - $_GET['page'] = 'gf_entries'; |
|
| 728 | + if ( 'fileupload' === $field->type ) { |
|
| 729 | + $_GET[ 'page' ] = 'gf_entries'; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
| 747 | 747 | |
| 748 | 748 | // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
| 749 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 749 | + if ( isset( $field->inputs ) && is_array( $field->inputs ) && ! in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 750 | 750 | |
| 751 | 751 | $field_value = array(); |
| 752 | 752 | |
@@ -755,10 +755,10 @@ discard block |
||
| 755 | 755 | |
| 756 | 756 | foreach ( (array)$field->inputs as $input ) { |
| 757 | 757 | |
| 758 | - $input_id = strval( $input['id'] ); |
|
| 758 | + $input_id = strval( $input[ 'id' ] ); |
|
| 759 | 759 | |
| 760 | 760 | if ( ! empty( $this->entry[ $input_id ] ) ) { |
| 761 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 761 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 762 | 762 | $allow_pre_populated = false; |
| 763 | 763 | } |
| 764 | 764 | |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | |
| 767 | 767 | $pre_value = $field->get_value_submission( array(), false ); |
| 768 | 768 | |
| 769 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !empty( $pre_value ) ) ? $field_value : $pre_value; |
|
| 769 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && ! empty( $pre_value ) ) ? $field_value : $pre_value; |
|
| 770 | 770 | |
| 771 | 771 | } else { |
| 772 | 772 | |
@@ -777,13 +777,13 @@ discard block |
||
| 777 | 777 | |
| 778 | 778 | // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
| 779 | 779 | // or pre-populated value if not empty and set to override saved value |
| 780 | - $field_value = !empty( $this->entry[ $id ] ) && ! ( $override_saved_value && !empty( $pre_value ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 780 | + $field_value = ! empty( $this->entry[ $id ] ) && ! ( $override_saved_value && ! empty( $pre_value ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 781 | 781 | |
| 782 | 782 | // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
| 783 | - if ( 'post_category' === $field->type && !empty( $field_value ) ) { |
|
| 783 | + if ( 'post_category' === $field->type && ! empty( $field_value ) ) { |
|
| 784 | 784 | $categories = array(); |
| 785 | 785 | foreach ( explode( ',', $field_value ) as $cat_string ) { |
| 786 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 786 | + $categories[ ] = GFCommon::format_post_category( $cat_string, true ); |
|
| 787 | 787 | } |
| 788 | 788 | $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
| 789 | 789 | } |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | // If there was output, it's an error |
| 810 | 810 | $warnings = ob_get_clean(); |
| 811 | 811 | |
| 812 | - if( !empty( $warnings ) ) { |
|
| 812 | + if ( ! empty( $warnings ) ) { |
|
| 813 | 813 | do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
| 814 | 814 | } |
| 815 | 815 | |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | * We need the fileupload html field to render with the proper id |
| 819 | 819 | * ( <li id="field_80_16" ... > ) |
| 820 | 820 | */ |
| 821 | - unset( $_GET['page'] ); |
|
| 821 | + unset( $_GET[ 'page' ] ); |
|
| 822 | 822 | |
| 823 | 823 | return $return; |
| 824 | 824 | } |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | public function get_field_value( $value, $lead, $field ) { |
| 838 | 838 | |
| 839 | 839 | // The form's not being edited; use the original value |
| 840 | - if( ! $this->is_edit_entry_submission() ) { |
|
| 840 | + if ( ! $this->is_edit_entry_submission() ) { |
|
| 841 | 841 | return $value; |
| 842 | 842 | } |
| 843 | 843 | |
@@ -858,12 +858,12 @@ discard block |
||
| 858 | 858 | */ |
| 859 | 859 | function gform_pre_validation( $form ) { |
| 860 | 860 | |
| 861 | - if( ! $this->verify_nonce() ) { |
|
| 861 | + if ( ! $this->verify_nonce() ) { |
|
| 862 | 862 | return $form; |
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | // Fix PHP warning regarding undefined index. |
| 866 | - foreach ( $form['fields'] as &$field) { |
|
| 866 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 867 | 867 | |
| 868 | 868 | // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
| 869 | 869 | // expects certain field array items to be set. |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | $field['emailConfirmEnabled'] = ''; |
| 877 | 877 | }*/ |
| 878 | 878 | |
| 879 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 879 | + switch ( RGFormsModel::get_input_type( $field ) ) { |
|
| 880 | 880 | |
| 881 | 881 | /** |
| 882 | 882 | * 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. |
@@ -891,38 +891,38 @@ discard block |
||
| 891 | 891 | // Set the previous value |
| 892 | 892 | $entry = $this->get_entry(); |
| 893 | 893 | |
| 894 | - $input_name = 'input_'.$field->id; |
|
| 895 | - $form_id = $form['id']; |
|
| 894 | + $input_name = 'input_' . $field->id; |
|
| 895 | + $form_id = $form[ 'id' ]; |
|
| 896 | 896 | |
| 897 | 897 | $value = NULL; |
| 898 | 898 | |
| 899 | 899 | // Use the previous entry value as the default. |
| 900 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 900 | + if ( isset( $entry[ $field->id ] ) ) { |
|
| 901 | 901 | $value = $entry[ $field->id ]; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | // If this is a single upload file |
| 905 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 906 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 907 | - $value = $file_path['url']; |
|
| 905 | + if ( ! empty( $_FILES[ $input_name ] ) && ! empty( $_FILES[ $input_name ][ 'name' ] ) ) { |
|
| 906 | + $file_path = GFFormsModel::get_file_upload_path( $form[ 'id' ], $_FILES[ $input_name ][ 'name' ] ); |
|
| 907 | + $value = $file_path[ 'url' ]; |
|
| 908 | 908 | |
| 909 | 909 | } else { |
| 910 | 910 | |
| 911 | 911 | // Fix PHP warning on line 1498 of form_display.php for post_image fields |
| 912 | 912 | // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
| 913 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 913 | + $_FILES[ $input_name ] = array( 'name' => '', 'size' => '' ); |
|
| 914 | 914 | |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | - if( rgar($field, "multipleFiles") ) { |
|
| 917 | + if ( rgar( $field, "multipleFiles" ) ) { |
|
| 918 | 918 | |
| 919 | 919 | // If there are fresh uploads, process and merge them. |
| 920 | 920 | // Otherwise, use the passed values, which should be json-encoded array of URLs |
| 921 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 921 | + if ( isset( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ) { |
|
| 922 | 922 | |
| 923 | 923 | $value = empty( $value ) ? '[]' : $value; |
| 924 | 924 | $value = stripslashes_deep( $value ); |
| 925 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 925 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ], array() ); |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | } else { |
@@ -938,14 +938,14 @@ discard block |
||
| 938 | 938 | break; |
| 939 | 939 | case 'number': |
| 940 | 940 | // Fix "undefined index" issue at line 1286 in form_display.php |
| 941 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 942 | - $_POST['input_'.$field->id ] = NULL; |
|
| 941 | + if ( ! isset( $_POST[ 'input_' . $field->id ] ) ) { |
|
| 942 | + $_POST[ 'input_' . $field->id ] = NULL; |
|
| 943 | 943 | } |
| 944 | 944 | break; |
| 945 | 945 | case 'captcha': |
| 946 | 946 | // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
| 947 | - $_POST['recaptcha_challenge_field'] = NULL; |
|
| 948 | - $_POST['recaptcha_response_field'] = NULL; |
|
| 947 | + $_POST[ 'recaptcha_challenge_field' ] = NULL; |
|
| 948 | + $_POST[ 'recaptcha_response_field' ] = NULL; |
|
| 949 | 949 | break; |
| 950 | 950 | } |
| 951 | 951 | |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | * You can enter whatever you want! |
| 975 | 975 | * We try validating, and customize the results using `self::custom_validation()` |
| 976 | 976 | */ |
| 977 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 977 | + add_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10, 4 ); |
|
| 978 | 978 | |
| 979 | 979 | // Needed by the validate funtion |
| 980 | 980 | $failed_validation_page = NULL; |
@@ -982,14 +982,14 @@ discard block |
||
| 982 | 982 | |
| 983 | 983 | // Prevent entry limit from running when editing an entry, also |
| 984 | 984 | // prevent form scheduling from preventing editing |
| 985 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 985 | + unset( $this->form[ 'limitEntries' ], $this->form[ 'scheduleForm' ] ); |
|
| 986 | 986 | |
| 987 | 987 | // Hide fields depending on Edit Entry settings |
| 988 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 988 | + $this->form[ 'fields' ] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 989 | 989 | |
| 990 | 990 | $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
| 991 | 991 | |
| 992 | - remove_filter( 'gform_validation_'.$this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 992 | + remove_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | 995 | |
@@ -1006,13 +1006,13 @@ discard block |
||
| 1006 | 1006 | */ |
| 1007 | 1007 | function custom_validation( $validation_results ) { |
| 1008 | 1008 | |
| 1009 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1009 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1010 | 1010 | |
| 1011 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1011 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1012 | 1012 | |
| 1013 | 1013 | $gv_valid = true; |
| 1014 | 1014 | |
| 1015 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1015 | + foreach ( $validation_results[ 'form' ][ 'fields' ] as $key => &$field ) { |
|
| 1016 | 1016 | |
| 1017 | 1017 | $value = RGFormsModel::get_field_value( $field ); |
| 1018 | 1018 | $field_type = RGFormsModel::get_input_type( $field ); |
@@ -1024,35 +1024,35 @@ discard block |
||
| 1024 | 1024 | case 'fileupload' : |
| 1025 | 1025 | |
| 1026 | 1026 | // in case nothing is uploaded but there are already files saved |
| 1027 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1027 | + if ( ! empty( $field->failed_validation ) && ! empty( $field->isRequired ) && ! empty( $value ) ) { |
|
| 1028 | 1028 | $field->failed_validation = false; |
| 1029 | 1029 | unset( $field->validation_message ); |
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | // validate if multi file upload reached max number of files [maxFiles] => 2 |
| 1033 | - if( rgar( $field, 'maxFiles') && rgar( $field, 'multipleFiles') ) { |
|
| 1033 | + if ( rgar( $field, 'maxFiles' ) && rgar( $field, 'multipleFiles' ) ) { |
|
| 1034 | 1034 | |
| 1035 | 1035 | $input_name = 'input_' . $field->id; |
| 1036 | 1036 | //uploaded |
| 1037 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1037 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] : array(); |
|
| 1038 | 1038 | |
| 1039 | 1039 | //existent |
| 1040 | 1040 | $entry = $this->get_entry(); |
| 1041 | 1041 | $value = NULL; |
| 1042 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1042 | + if ( isset( $entry[ $field->id ] ) ) { |
|
| 1043 | 1043 | $value = json_decode( $entry[ $field->id ], true ); |
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | // count uploaded files and existent entry files |
| 1047 | 1047 | $count_files = count( $file_names ) + count( $value ); |
| 1048 | 1048 | |
| 1049 | - if( $count_files > $field->maxFiles ) { |
|
| 1049 | + if ( $count_files > $field->maxFiles ) { |
|
| 1050 | 1050 | $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
| 1051 | 1051 | $field->failed_validation = 1; |
| 1052 | 1052 | $gv_valid = false; |
| 1053 | 1053 | |
| 1054 | 1054 | // in case of error make sure the newest upload files are removed from the upload input |
| 1055 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1055 | + GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ] = null; |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | } |
@@ -1063,7 +1063,7 @@ discard block |
||
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | // This field has failed validation. |
| 1066 | - if( !empty( $field->failed_validation ) ) { |
|
| 1066 | + if ( ! empty( $field->failed_validation ) ) { |
|
| 1067 | 1067 | |
| 1068 | 1068 | do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
| 1069 | 1069 | |
@@ -1081,32 +1081,32 @@ discard block |
||
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | // You can't continue inside a switch, so we do it after. |
| 1084 | - if( empty( $field->failed_validation ) ) { |
|
| 1084 | + if ( empty( $field->failed_validation ) ) { |
|
| 1085 | 1085 | continue; |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | // checks if the No Duplicates option is not validating entry against itself, since |
| 1089 | 1089 | // we're editing a stored entry, it would also assume it's a duplicate. |
| 1090 | - if( !empty( $field->noDuplicates ) ) { |
|
| 1090 | + if ( ! empty( $field->noDuplicates ) ) { |
|
| 1091 | 1091 | |
| 1092 | 1092 | $entry = $this->get_entry(); |
| 1093 | 1093 | |
| 1094 | 1094 | // If the value of the entry is the same as the stored value |
| 1095 | 1095 | // Then we can assume it's not a duplicate, it's the same. |
| 1096 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1096 | + if ( ! empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1097 | 1097 | //if value submitted was not changed, then don't validate |
| 1098 | 1098 | $field->failed_validation = false; |
| 1099 | 1099 | |
| 1100 | 1100 | unset( $field->validation_message ); |
| 1101 | 1101 | |
| 1102 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1102 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1103 | 1103 | |
| 1104 | 1104 | continue; |
| 1105 | 1105 | } |
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | // if here then probably we are facing the validation 'At least one field must be filled out' |
| 1109 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1109 | + if ( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1110 | 1110 | unset( $field->validation_message ); |
| 1111 | 1111 | $field->validation_message = false; |
| 1112 | 1112 | continue; |
@@ -1118,12 +1118,12 @@ discard block |
||
| 1118 | 1118 | |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - $validation_results['is_valid'] = $gv_valid; |
|
| 1121 | + $validation_results[ 'is_valid' ] = $gv_valid; |
|
| 1122 | 1122 | |
| 1123 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1123 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1124 | 1124 | |
| 1125 | 1125 | // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
| 1126 | - $this->form_after_validation = $validation_results['form']; |
|
| 1126 | + $this->form_after_validation = $validation_results[ 'form' ]; |
|
| 1127 | 1127 | |
| 1128 | 1128 | return $validation_results; |
| 1129 | 1129 | } |
@@ -1136,7 +1136,7 @@ discard block |
||
| 1136 | 1136 | */ |
| 1137 | 1137 | private function get_entry() { |
| 1138 | 1138 | |
| 1139 | - if( empty( $this->entry ) ) { |
|
| 1139 | + if ( empty( $this->entry ) ) { |
|
| 1140 | 1140 | // Get the database value of the entry that's being edited |
| 1141 | 1141 | $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
| 1142 | 1142 | } |
@@ -1163,13 +1163,13 @@ discard block |
||
| 1163 | 1163 | $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
| 1164 | 1164 | |
| 1165 | 1165 | // If edit tab not yet configured, show all fields |
| 1166 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1166 | + $edit_fields = ! empty( $properties[ 'edit_edit-fields' ] ) ? $properties[ 'edit_edit-fields' ] : NULL; |
|
| 1167 | 1167 | |
| 1168 | 1168 | // Show hidden fields as text fields |
| 1169 | 1169 | $form = $this->fix_hidden_fields( $form ); |
| 1170 | 1170 | |
| 1171 | 1171 | // Hide fields depending on admin settings |
| 1172 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1172 | + $fields = $this->filter_fields( $form[ 'fields' ], $edit_fields ); |
|
| 1173 | 1173 | |
| 1174 | 1174 | // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
| 1175 | 1175 | $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
@@ -1187,11 +1187,11 @@ discard block |
||
| 1187 | 1187 | private function fix_hidden_fields( $form ) { |
| 1188 | 1188 | |
| 1189 | 1189 | /** @var GF_Field $field */ |
| 1190 | - foreach( $form['fields'] as $key => $field ) { |
|
| 1191 | - if( 'hidden' === $field->type ) { |
|
| 1190 | + foreach ( $form[ 'fields' ] as $key => $field ) { |
|
| 1191 | + if ( 'hidden' === $field->type ) { |
|
| 1192 | 1192 | $text_field = new GF_Field_Text( $field ); |
| 1193 | 1193 | $text_field->type = 'text'; |
| 1194 | - $form['fields'][ $key ] = $text_field; |
|
| 1194 | + $form[ 'fields' ][ $key ] = $text_field; |
|
| 1195 | 1195 | } |
| 1196 | 1196 | } |
| 1197 | 1197 | |
@@ -1211,7 +1211,7 @@ discard block |
||
| 1211 | 1211 | */ |
| 1212 | 1212 | private function filter_fields( $fields, $configured_fields ) { |
| 1213 | 1213 | |
| 1214 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1214 | + if ( empty( $fields ) || ! is_array( $fields ) ) { |
|
| 1215 | 1215 | return $fields; |
| 1216 | 1216 | } |
| 1217 | 1217 | |
@@ -1228,24 +1228,24 @@ discard block |
||
| 1228 | 1228 | */ |
| 1229 | 1229 | $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
| 1230 | 1230 | |
| 1231 | - if( $hide_product_fields ) { |
|
| 1232 | - $field_type_blacklist[] = 'option'; |
|
| 1233 | - $field_type_blacklist[] = 'quantity'; |
|
| 1234 | - $field_type_blacklist[] = 'product'; |
|
| 1235 | - $field_type_blacklist[] = 'total'; |
|
| 1236 | - $field_type_blacklist[] = 'shipping'; |
|
| 1237 | - $field_type_blacklist[] = 'calculation'; |
|
| 1231 | + if ( $hide_product_fields ) { |
|
| 1232 | + $field_type_blacklist[ ] = 'option'; |
|
| 1233 | + $field_type_blacklist[ ] = 'quantity'; |
|
| 1234 | + $field_type_blacklist[ ] = 'product'; |
|
| 1235 | + $field_type_blacklist[ ] = 'total'; |
|
| 1236 | + $field_type_blacklist[ ] = 'shipping'; |
|
| 1237 | + $field_type_blacklist[ ] = 'calculation'; |
|
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | // First, remove blacklist |
| 1241 | 1241 | foreach ( $fields as $key => $field ) { |
| 1242 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1242 | + if ( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1243 | 1243 | unset( $fields[ $key ] ); |
| 1244 | 1244 | } |
| 1245 | 1245 | } |
| 1246 | 1246 | |
| 1247 | 1247 | // The Edit tab has not been configured, so we return all fields by default. |
| 1248 | - if( empty( $configured_fields ) ) { |
|
| 1248 | + if ( empty( $configured_fields ) ) { |
|
| 1249 | 1249 | return $fields; |
| 1250 | 1250 | } |
| 1251 | 1251 | |
@@ -1255,8 +1255,8 @@ discard block |
||
| 1255 | 1255 | /** @var GF_Field $field */ |
| 1256 | 1256 | foreach ( $fields as $field ) { |
| 1257 | 1257 | |
| 1258 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1259 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1258 | + if ( intval( $configured_field[ 'id' ] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1259 | + $edit_fields[ ] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1260 | 1260 | break; |
| 1261 | 1261 | } |
| 1262 | 1262 | |
@@ -1279,14 +1279,14 @@ discard block |
||
| 1279 | 1279 | |
| 1280 | 1280 | $return_field = $field; |
| 1281 | 1281 | |
| 1282 | - if( empty( $field_setting['show_label'] ) ) { |
|
| 1282 | + if ( empty( $field_setting[ 'show_label' ] ) ) { |
|
| 1283 | 1283 | $return_field->label = ''; |
| 1284 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1285 | - $return_field->label = $field_setting['custom_label']; |
|
| 1284 | + } elseif ( ! empty( $field_setting[ 'custom_label' ] ) ) { |
|
| 1285 | + $return_field->label = $field_setting[ 'custom_label' ]; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1289 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1288 | + if ( ! empty( $field_setting[ 'custom_class' ] ) ) { |
|
| 1289 | + $return_field->cssClass .= ' ' . gravityview_sanitize_html_class( $field_setting[ 'custom_class' ] ); |
|
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | /** |
@@ -1324,11 +1324,11 @@ discard block |
||
| 1324 | 1324 | */ |
| 1325 | 1325 | $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
| 1326 | 1326 | |
| 1327 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1327 | + if ( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry[ 'id' ] ) ) { |
|
| 1328 | 1328 | return $fields; |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - foreach( $fields as &$field ) { |
|
| 1331 | + foreach ( $fields as &$field ) { |
|
| 1332 | 1332 | $field->adminOnly = false; |
| 1333 | 1333 | } |
| 1334 | 1334 | |
@@ -1355,16 +1355,16 @@ discard block |
||
| 1355 | 1355 | */ |
| 1356 | 1356 | $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
| 1357 | 1357 | |
| 1358 | - if( $use_conditional_logic ) { |
|
| 1358 | + if ( $use_conditional_logic ) { |
|
| 1359 | 1359 | return $form; |
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | - foreach( $form['fields'] as &$field ) { |
|
| 1362 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 1363 | 1363 | /* @var GF_Field $field */ |
| 1364 | 1364 | $field->conditionalLogic = null; |
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | - unset( $form['button']['conditionalLogic'] ); |
|
| 1367 | + unset( $form[ 'button' ][ 'conditionalLogic' ] ); |
|
| 1368 | 1368 | |
| 1369 | 1369 | return $form; |
| 1370 | 1370 | |
@@ -1381,7 +1381,7 @@ discard block |
||
| 1381 | 1381 | */ |
| 1382 | 1382 | function manage_conditional_logic( $has_conditional_logic, $form ) { |
| 1383 | 1383 | |
| 1384 | - if( ! $this->is_edit_entry() ) { |
|
| 1384 | + if ( ! $this->is_edit_entry() ) { |
|
| 1385 | 1385 | return $has_conditional_logic; |
| 1386 | 1386 | } |
| 1387 | 1387 | |
@@ -1413,44 +1413,44 @@ discard block |
||
| 1413 | 1413 | * 2. There are two entries embedded using oEmbed |
| 1414 | 1414 | * 3. One of the entries has just been saved |
| 1415 | 1415 | */ |
| 1416 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1416 | + if ( ! empty( $_POST[ 'lid' ] ) && ! empty( $_GET[ 'entry' ] ) && ( $_POST[ 'lid' ] !== $_GET[ 'entry' ] ) ) { |
|
| 1417 | 1417 | |
| 1418 | 1418 | $error = true; |
| 1419 | 1419 | |
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1422 | + if ( ! empty( $_GET[ 'entry' ] ) && (string)$this->entry[ 'id' ] !== $_GET[ 'entry' ] ) { |
|
| 1423 | 1423 | |
| 1424 | 1424 | $error = true; |
| 1425 | 1425 | |
| 1426 | - } elseif( ! $this->verify_nonce() ) { |
|
| 1426 | + } elseif ( ! $this->verify_nonce() ) { |
|
| 1427 | 1427 | |
| 1428 | 1428 | /** |
| 1429 | 1429 | * If the Entry is embedded, there may be two entries on the same page. |
| 1430 | 1430 | * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
| 1431 | 1431 | */ |
| 1432 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1432 | + if ( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1433 | 1433 | $error = true; |
| 1434 | 1434 | } else { |
| 1435 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1435 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview' ); |
|
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1441 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1440 | + if ( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1441 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview' ); |
|
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | - if( $this->entry['status'] === 'trash' ) { |
|
| 1445 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1444 | + if ( $this->entry[ 'status' ] === 'trash' ) { |
|
| 1445 | + $error = __( 'You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | // No errors; everything's fine here! |
| 1449 | - if( empty( $error ) ) { |
|
| 1449 | + if ( empty( $error ) ) { |
|
| 1450 | 1450 | return true; |
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | - if( $echo && $error !== true ) { |
|
| 1453 | + if ( $echo && $error !== true ) { |
|
| 1454 | 1454 | |
| 1455 | 1455 | $error = esc_html( $error ); |
| 1456 | 1456 | |
@@ -1458,13 +1458,13 @@ discard block |
||
| 1458 | 1458 | * @since 1.9 |
| 1459 | 1459 | */ |
| 1460 | 1460 | if ( ! empty( $this->entry ) ) { |
| 1461 | - $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;" ) ); |
|
| 1461 | + $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;" ) ); |
|
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1464 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error' ); |
|
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1467 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1468 | 1468 | |
| 1469 | 1469 | return false; |
| 1470 | 1470 | } |
@@ -1481,20 +1481,20 @@ discard block |
||
| 1481 | 1481 | |
| 1482 | 1482 | $error = NULL; |
| 1483 | 1483 | |
| 1484 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1485 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1484 | + if ( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1485 | + $error = __( 'You do not have permission to edit this field.', 'gravityview' ); |
|
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | // No errors; everything's fine here! |
| 1489 | - if( empty( $error ) ) { |
|
| 1489 | + if ( empty( $error ) ) { |
|
| 1490 | 1490 | return true; |
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | - if( $echo ) { |
|
| 1494 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1493 | + if ( $echo ) { |
|
| 1494 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error' ); |
|
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 1497 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1497 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1498 | 1498 | |
| 1499 | 1499 | return false; |
| 1500 | 1500 | |
@@ -1512,15 +1512,15 @@ discard block |
||
| 1512 | 1512 | private function check_user_cap_edit_field( $field ) { |
| 1513 | 1513 | |
| 1514 | 1514 | // If they can edit any entries (as defined in Gravity Forms), we're good. |
| 1515 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1515 | + if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1516 | 1516 | return true; |
| 1517 | 1517 | } |
| 1518 | 1518 | |
| 1519 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1519 | + $field_cap = isset( $field[ 'allow_edit_cap' ] ) ? $field[ 'allow_edit_cap' ] : false; |
|
| 1520 | 1520 | |
| 1521 | 1521 | // If the field has custom editing capaibilities set, check those |
| 1522 | - if( $field_cap ) { |
|
| 1523 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1522 | + if ( $field_cap ) { |
|
| 1523 | + return GVCommon::has_cap( $field[ 'allow_edit_cap' ] ); |
|
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | 1526 | return false; |
@@ -1534,17 +1534,17 @@ discard block |
||
| 1534 | 1534 | public function verify_nonce() { |
| 1535 | 1535 | |
| 1536 | 1536 | // Verify form submitted for editing single |
| 1537 | - if( $this->is_edit_entry_submission() ) { |
|
| 1537 | + if ( $this->is_edit_entry_submission() ) { |
|
| 1538 | 1538 | $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
| 1539 | 1539 | } |
| 1540 | 1540 | |
| 1541 | 1541 | // Verify |
| 1542 | - else if( ! $this->is_edit_entry() ) { |
|
| 1542 | + else if ( ! $this->is_edit_entry() ) { |
|
| 1543 | 1543 | $valid = false; |
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | 1546 | else { |
| 1547 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 1547 | + $valid = wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ); |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | /** |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | var $name = 'post_category'; |
| 11 | 11 | |
| 12 | - var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains'); |
|
| 12 | + var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains' ); |
|
| 13 | 13 | |
| 14 | 14 | var $_gf_field_class_name = 'GF_Field_Post_Category'; |
| 15 | 15 | |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
| 24 | 24 | |
| 25 | - if( 'edit' === $context ) { |
|
| 25 | + if ( 'edit' === $context ) { |
|
| 26 | 26 | return $field_options; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - $this->add_field_support('dynamic_data', $field_options ); |
|
| 30 | - $this->add_field_support('link_to_term', $field_options ); |
|
| 29 | + $this->add_field_support( 'dynamic_data', $field_options ); |
|
| 30 | + $this->add_field_support( 'link_to_term', $field_options ); |
|
| 31 | 31 | |
| 32 | 32 | return $field_options; |
| 33 | 33 | } |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | |
| 10 | 10 | var $name = 'radio'; |
| 11 | 11 | |
| 12 | - var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains'); |
|
| 12 | + var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains' ); |
|
| 13 | 13 | |
| 14 | 14 | var $_gf_field_class_name = 'GF_Field_Radio'; |
| 15 | 15 | |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | |
| 10 | 10 | var $name = 'radio'; |
| 11 | 11 | |
| 12 | - var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains'); |
|
| 12 | + var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains' ); |
|
| 13 | 13 | |
| 14 | 14 | var $_gf_field_class_name = 'GF_Field_Radio'; |
| 15 | 15 | |