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