@@ -53,6 +53,9 @@ discard block |
||
53 | 53 | add_action( 'wp_ajax_gravityview_license', array( $this, 'license_call' ) ); |
54 | 54 | } |
55 | 55 | |
56 | + /** |
|
57 | + * @param boolean $echo |
|
58 | + */ |
|
56 | 59 | function settings_edd_license_activation( $field, $echo ) { |
57 | 60 | |
58 | 61 | wp_enqueue_script( 'gv-admin-edd-license', GRAVITYVIEW_URL . 'assets/js/admin-edd-license.js', array( 'jquery' ) ); |
@@ -241,7 +244,7 @@ discard block |
||
241 | 244 | * Generate the status message box HTML based on the current status |
242 | 245 | * |
243 | 246 | * @since 1.7.4 |
244 | - * @param $message |
|
247 | + * @param string $message |
|
245 | 248 | * @param string $class |
246 | 249 | * |
247 | 250 | * @return string |
@@ -340,7 +340,7 @@ |
||
340 | 340 | // Update option with passed data license |
341 | 341 | $settings = $this->Addon->get_app_settings(); |
342 | 342 | |
343 | - $settings['license_key'] = $license_data->license_key = trim( $data['license'] ); |
|
343 | + $settings['license_key'] = $license_data->license_key = trim( $data['license'] ); |
|
344 | 344 | $settings['license_key_status'] = $license_data->license; |
345 | 345 | $settings['license_key_response'] = (array)$license_data; |
346 | 346 |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return GV_License_Handler |
35 | 35 | */ |
36 | - public static function get_instance( GravityView_Settings $GFAddOn ) { |
|
37 | - if( empty( self::$instance ) ) { |
|
38 | - self::$instance = new self( $GFAddOn ); |
|
36 | + public static function get_instance(GravityView_Settings $GFAddOn) { |
|
37 | + if (empty(self::$instance)) { |
|
38 | + self::$instance = new self($GFAddOn); |
|
39 | 39 | } |
40 | 40 | return self::$instance; |
41 | 41 | } |
42 | 42 | |
43 | - private function __construct( GravityView_Settings $GFAddOn ) { |
|
43 | + private function __construct(GravityView_Settings $GFAddOn) { |
|
44 | 44 | |
45 | 45 | $this->Addon = $GFAddOn; |
46 | 46 | |
@@ -50,25 +50,25 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | private function add_hooks() { |
53 | - add_action( 'wp_ajax_gravityview_license', array( $this, 'license_call' ) ); |
|
53 | + add_action('wp_ajax_gravityview_license', array($this, 'license_call')); |
|
54 | 54 | } |
55 | 55 | |
56 | - function settings_edd_license_activation( $field, $echo ) { |
|
56 | + function settings_edd_license_activation($field, $echo) { |
|
57 | 57 | |
58 | - wp_enqueue_script( 'gv-admin-edd-license', GRAVITYVIEW_URL . 'assets/js/admin-edd-license.js', array( 'jquery' ) ); |
|
58 | + wp_enqueue_script('gv-admin-edd-license', GRAVITYVIEW_URL.'assets/js/admin-edd-license.js', array('jquery')); |
|
59 | 59 | |
60 | - $status = trim( $this->Addon->get_app_setting( 'license_key_status' ) ); |
|
61 | - $key = trim( $this->Addon->get_app_setting( 'license_key' ) ); |
|
60 | + $status = trim($this->Addon->get_app_setting('license_key_status')); |
|
61 | + $key = trim($this->Addon->get_app_setting('license_key')); |
|
62 | 62 | |
63 | - if( !empty( $key ) ) { |
|
64 | - $response = $this->Addon->get_app_setting( 'license_key_response' ); |
|
65 | - $response = is_array( $response ) ? (object) $response : json_decode( $response ); |
|
63 | + if (!empty($key)) { |
|
64 | + $response = $this->Addon->get_app_setting('license_key_response'); |
|
65 | + $response = is_array($response) ? (object)$response : json_decode($response); |
|
66 | 66 | } else { |
67 | 67 | $response = array(); |
68 | 68 | } |
69 | 69 | |
70 | - wp_localize_script( 'gv-admin-edd-license', 'GVGlobals', array( |
|
71 | - 'license_box' => $this->get_license_message( $response ) |
|
70 | + wp_localize_script('gv-admin-edd-license', 'GVGlobals', array( |
|
71 | + 'license_box' => $this->get_license_message($response) |
|
72 | 72 | )); |
73 | 73 | |
74 | 74 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | 'value' => __('Deactivate License', 'gravityview'), |
86 | 86 | 'data-pending_text' => __('Deactivating license…', 'gravityview'), |
87 | 87 | 'data-edd_action' => 'deactivate_license', |
88 | - 'class' => ( empty( $status ) ? 'button-primary hide' : 'button-primary' ), |
|
88 | + 'class' => (empty($status) ? 'button-primary hide' : 'button-primary'), |
|
89 | 89 | ), |
90 | 90 | array( |
91 | 91 | 'name' => 'edd-check', |
@@ -100,19 +100,19 @@ discard block |
||
100 | 100 | |
101 | 101 | $class = 'button gv-edd-action'; |
102 | 102 | |
103 | - $class .= ( !empty( $key ) && $status !== 'valid' ) ? '' : ' hide'; |
|
103 | + $class .= (!empty($key) && $status !== 'valid') ? '' : ' hide'; |
|
104 | 104 | |
105 | - $disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled'; |
|
105 | + $disabled_attribute = GVCommon::has_cap('gravityview_edit_settings') ? false : 'disabled'; |
|
106 | 106 | |
107 | 107 | $submit = '<div class="gv-edd-button-wrapper">'; |
108 | - foreach ( $fields as $field ) { |
|
108 | + foreach ($fields as $field) { |
|
109 | 109 | $field['type'] = 'button'; |
110 | - $field['class'] = isset( $field['class'] ) ? $field['class'] . ' '. $class : $class; |
|
110 | + $field['class'] = isset($field['class']) ? $field['class'].' '.$class : $class; |
|
111 | 111 | $field['style'] = 'margin-left: 10px;'; |
112 | - if( $disabled_attribute ) { |
|
112 | + if ($disabled_attribute) { |
|
113 | 113 | $field['disabled'] = $disabled_attribute; |
114 | 114 | } |
115 | - $submit .= $this->Addon->settings_submit( $field, $echo ); |
|
115 | + $submit .= $this->Addon->settings_submit($field, $echo); |
|
116 | 116 | } |
117 | 117 | $submit .= '</div>'; |
118 | 118 | |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | */ |
127 | 127 | private function setup_edd() { |
128 | 128 | |
129 | - if( !class_exists('EDD_SL_Plugin_Updater') ) { |
|
130 | - require_once( GRAVITYVIEW_DIR . 'includes/lib/EDD_SL_Plugin_Updater.php'); |
|
129 | + if (!class_exists('EDD_SL_Plugin_Updater')) { |
|
130 | + require_once(GRAVITYVIEW_DIR.'includes/lib/EDD_SL_Plugin_Updater.php'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | // setup the updater |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return array |
151 | 151 | */ |
152 | - function _get_edd_settings( $action = '', $license = '' ) { |
|
152 | + function _get_edd_settings($action = '', $license = '') { |
|
153 | 153 | |
154 | 154 | // retrieve our license key from the DB |
155 | - $license_key = empty( $license ) ? trim( $this->Addon->get_app_setting( 'license_key' ) ) : $license; |
|
155 | + $license_key = empty($license) ? trim($this->Addon->get_app_setting('license_key')) : $license; |
|
156 | 156 | |
157 | 157 | $settings = array( |
158 | 158 | 'version' => self::version, |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | 'url' => home_url(), |
164 | 164 | ); |
165 | 165 | |
166 | - if( !empty( $action ) ) { |
|
167 | - $settings['edd_action'] = esc_attr( $action ); |
|
166 | + if (!empty($action)) { |
|
167 | + $settings['edd_action'] = esc_attr($action); |
|
168 | 168 | } |
169 | 169 | |
170 | - $settings = array_map( 'urlencode', $settings ); |
|
170 | + $settings = array_map('urlencode', $settings); |
|
171 | 171 | |
172 | 172 | return $settings; |
173 | 173 | } |
@@ -176,27 +176,27 @@ discard block |
||
176 | 176 | * Perform the call |
177 | 177 | * @return array|WP_Error |
178 | 178 | */ |
179 | - private function _license_get_remote_response( $data, $license = '' ) { |
|
179 | + private function _license_get_remote_response($data, $license = '') { |
|
180 | 180 | |
181 | - $api_params = $this->_get_edd_settings( $data['edd_action'], $license ); |
|
181 | + $api_params = $this->_get_edd_settings($data['edd_action'], $license); |
|
182 | 182 | |
183 | - $url = add_query_arg( $api_params, self::url ); |
|
183 | + $url = add_query_arg($api_params, self::url); |
|
184 | 184 | |
185 | - $response = wp_remote_get( $url, array( |
|
185 | + $response = wp_remote_get($url, array( |
|
186 | 186 | 'timeout' => 15, |
187 | 187 | 'sslverify' => false, |
188 | 188 | )); |
189 | 189 | |
190 | - if ( is_wp_error( $response ) ) { |
|
190 | + if (is_wp_error($response)) { |
|
191 | 191 | return array(); |
192 | 192 | } |
193 | 193 | |
194 | - $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
194 | + $license_data = json_decode(wp_remote_retrieve_body($response)); |
|
195 | 195 | |
196 | 196 | // Not JSON |
197 | - if ( empty( $license_data ) ) { |
|
197 | + if (empty($license_data)) { |
|
198 | 198 | |
199 | - delete_transient( 'gravityview_' . esc_attr( $data['field_id'] ) . '_valid' ); |
|
199 | + delete_transient('gravityview_'.esc_attr($data['field_id']).'_valid'); |
|
200 | 200 | |
201 | 201 | // Change status |
202 | 202 | return array(); |
@@ -216,14 +216,14 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return string |
218 | 218 | */ |
219 | - function get_license_message( $license_data ) { |
|
219 | + function get_license_message($license_data) { |
|
220 | 220 | |
221 | - if( empty( $license_data ) ) { |
|
221 | + if (empty($license_data)) { |
|
222 | 222 | $class = 'hide'; |
223 | 223 | $message = ''; |
224 | 224 | } else { |
225 | 225 | |
226 | - if( ! empty( $license_data->error ) ) { |
|
226 | + if (!empty($license_data->error)) { |
|
227 | 227 | $class = 'error'; |
228 | 228 | $string_key = $license_data->error; |
229 | 229 | } else { |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | $string_key = $license_data->license; |
232 | 232 | } |
233 | 233 | |
234 | - $message = sprintf( '<p><strong>%s: %s</strong></p>', $this->strings('status'), $this->strings( $string_key, $license_data ) ); |
|
234 | + $message = sprintf('<p><strong>%s: %s</strong></p>', $this->strings('status'), $this->strings($string_key, $license_data)); |
|
235 | 235 | } |
236 | 236 | |
237 | - return $this->generate_license_box( $message, $class ); |
|
237 | + return $this->generate_license_box($message, $class); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -246,11 +246,11 @@ discard block |
||
246 | 246 | * |
247 | 247 | * @return string |
248 | 248 | */ |
249 | - private function generate_license_box( $message, $class = '' ) { |
|
249 | + private function generate_license_box($message, $class = '') { |
|
250 | 250 | |
251 | 251 | $template = '<div id="gv-edd-status" class="gv-edd-message inline %s">%s</div>'; |
252 | 252 | |
253 | - $output = sprintf( $template, esc_attr( $class ), $message ); |
|
253 | + $output = sprintf($template, esc_attr($class), $message); |
|
254 | 254 | |
255 | 255 | return $output; |
256 | 256 | } |
@@ -270,63 +270,63 @@ discard block |
||
270 | 270 | * |
271 | 271 | * @return mixed|string|void |
272 | 272 | */ |
273 | - public function license_call( $array = array() ) { |
|
273 | + public function license_call($array = array()) { |
|
274 | 274 | |
275 | - $is_ajax = ( defined('DOING_AJAX') && DOING_AJAX ); |
|
276 | - $data = empty( $array ) ? $_POST['data'] : $array; |
|
277 | - $has_cap = GVCommon::has_cap( 'gravityview_edit_settings' ); |
|
275 | + $is_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
|
276 | + $data = empty($array) ? $_POST['data'] : $array; |
|
277 | + $has_cap = GVCommon::has_cap('gravityview_edit_settings'); |
|
278 | 278 | |
279 | - if ( $is_ajax && empty( $data['license'] ) ) { |
|
280 | - die( - 1 ); |
|
279 | + if ($is_ajax && empty($data['license'])) { |
|
280 | + die( -1 ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | // If the user isn't allowed to edit settings, show an error message |
284 | - if( ! $has_cap ) { |
|
284 | + if (!$has_cap) { |
|
285 | 285 | $license_data = new stdClass(); |
286 | 286 | $license_data->error = 'capability'; |
287 | - $license_data->message = $this->get_license_message( $license_data ); |
|
288 | - $json = json_encode( $license_data ); |
|
287 | + $license_data->message = $this->get_license_message($license_data); |
|
288 | + $json = json_encode($license_data); |
|
289 | 289 | } else { |
290 | 290 | |
291 | - $license = esc_attr( rgget( 'license', $data ) ); |
|
292 | - $license_data = $this->_license_get_remote_response( $data, $license ); |
|
291 | + $license = esc_attr(rgget('license', $data)); |
|
292 | + $license_data = $this->_license_get_remote_response($data, $license); |
|
293 | 293 | |
294 | 294 | // Empty is returned when there's an error. |
295 | - if ( empty( $license_data ) ) { |
|
296 | - if ( $is_ajax ) { |
|
297 | - exit( json_encode( array() ) ); |
|
295 | + if (empty($license_data)) { |
|
296 | + if ($is_ajax) { |
|
297 | + exit(json_encode(array())); |
|
298 | 298 | } else { // Non-ajax call |
299 | - return json_encode( array() ); |
|
299 | + return json_encode(array()); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - $license_data->message = $this->get_license_message( $license_data ); |
|
303 | + $license_data->message = $this->get_license_message($license_data); |
|
304 | 304 | |
305 | - $json = json_encode( $license_data ); |
|
305 | + $json = json_encode($license_data); |
|
306 | 306 | |
307 | - $update_license = ( ! isset( $data['update'] ) || ! empty( $data['update'] ) ); |
|
307 | + $update_license = (!isset($data['update']) || !empty($data['update'])); |
|
308 | 308 | |
309 | - $is_check_action_button = ( 'check_license' === $data['edd_action'] && defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
309 | + $is_check_action_button = ('check_license' === $data['edd_action'] && defined('DOING_AJAX') && DOING_AJAX); |
|
310 | 310 | |
311 | 311 | // Failed is the response from trying to de-activate a license and it didn't work. |
312 | 312 | // This likely happened because people entered in a different key and clicked "Deactivate", |
313 | 313 | // meaning to deactivate the original key. We don't want to save this response, since it is |
314 | 314 | // most likely a mistake. |
315 | - if ( $license_data->license !== 'failed' && ! $is_check_action_button && $update_license ) { |
|
315 | + if ($license_data->license !== 'failed' && !$is_check_action_button && $update_license) { |
|
316 | 316 | |
317 | - if ( ! empty( $data['field_id'] ) ) { |
|
318 | - set_transient( 'gravityview_' . esc_attr( $data['field_id'] ) . '_valid', $license_data, DAY_IN_SECONDS ); |
|
317 | + if (!empty($data['field_id'])) { |
|
318 | + set_transient('gravityview_'.esc_attr($data['field_id']).'_valid', $license_data, DAY_IN_SECONDS); |
|
319 | 319 | } |
320 | 320 | |
321 | - $this->license_call_update_settings( $license_data, $data ); |
|
321 | + $this->license_call_update_settings($license_data, $data); |
|
322 | 322 | |
323 | 323 | } |
324 | 324 | } // End $has_cap |
325 | 325 | |
326 | - if ( $is_ajax ) { |
|
327 | - exit( $json ); |
|
326 | + if ($is_ajax) { |
|
327 | + exit($json); |
|
328 | 328 | } else { // Non-ajax call |
329 | - return ( rgget('format', $data ) === 'object' ) ? $license_data : $json; |
|
329 | + return (rgget('format', $data) === 'object') ? $license_data : $json; |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
@@ -335,16 +335,16 @@ discard block |
||
335 | 335 | * @param object $license_data |
336 | 336 | * @return void |
337 | 337 | */ |
338 | - private function license_call_update_settings( $license_data, $data ) { |
|
338 | + private function license_call_update_settings($license_data, $data) { |
|
339 | 339 | |
340 | 340 | // Update option with passed data license |
341 | 341 | $settings = $this->Addon->get_app_settings(); |
342 | 342 | |
343 | - $settings['license_key'] = $license_data->license_key = trim( $data['license'] ); |
|
343 | + $settings['license_key'] = $license_data->license_key = trim($data['license']); |
|
344 | 344 | $settings['license_key_status'] = $license_data->license; |
345 | 345 | $settings['license_key_response'] = (array)$license_data; |
346 | 346 | |
347 | - $this->Addon->update_app_settings( $settings ); |
|
347 | + $this->Addon->update_app_settings($settings); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -353,8 +353,8 @@ discard block |
||
353 | 353 | * @param object|null $license_data Object with license data |
354 | 354 | * @return string Renewal or account URL |
355 | 355 | */ |
356 | - private function get_license_renewal_url( $license_data ) { |
|
357 | - $renew_license_url = ( ! empty( $license_data ) && !empty( $license_data->license_key ) ) ? sprintf( 'https://gravityview.co/checkout/?download_id=17&edd_license_key=%s&utm_source=admin_notice&utm_medium=admin&utm_content=expired&utm_campaign=Activation', $license_data->license_key ) : 'https://gravityview.co/account/'; |
|
356 | + private function get_license_renewal_url($license_data) { |
|
357 | + $renew_license_url = (!empty($license_data) && !empty($license_data->license_key)) ? sprintf('https://gravityview.co/checkout/?download_id=17&edd_license_key=%s&utm_source=admin_notice&utm_medium=admin&utm_content=expired&utm_campaign=Activation', $license_data->license_key) : 'https://gravityview.co/account/'; |
|
358 | 358 | return $renew_license_url; |
359 | 359 | } |
360 | 360 | |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * @param object|null $license_data Object with license data |
365 | 365 | * @return array Modified array of content |
366 | 366 | */ |
367 | - public function strings( $status = NULL, $license_data = null ) { |
|
367 | + public function strings($status = NULL, $license_data = null) { |
|
368 | 368 | |
369 | 369 | |
370 | 370 | $strings = array( |
@@ -372,14 +372,14 @@ discard block |
||
372 | 372 | 'error' => esc_html__('There was an error processing the request.', 'gravityview'), |
373 | 373 | 'failed' => esc_html__('Could not deactivate the license. The license key you attempted to deactivate may not be active or valid.', 'gravityview'), |
374 | 374 | 'site_inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'), |
375 | - 'no_activations_left' => esc_html__('Invalid: this license has reached its activation limit.', 'gravityview') . ' ' . sprintf( esc_html__('You can manage license activations %son your GravityView account page%s.', 'gravityview'), '<a href="https://gravityview.co/account/#licenses">', '</a>' ), |
|
375 | + 'no_activations_left' => esc_html__('Invalid: this license has reached its activation limit.', 'gravityview').' '.sprintf(esc_html__('You can manage license activations %son your GravityView account page%s.', 'gravityview'), '<a href="https://gravityview.co/account/#licenses">', '</a>'), |
|
376 | 376 | 'deactivated' => esc_html__('The license has been deactivated.', 'gravityview'), |
377 | 377 | 'valid' => esc_html__('The license key is valid and active.', 'gravityview'), |
378 | 378 | 'invalid' => esc_html__('The license key entered is invalid.', 'gravityview'), |
379 | 379 | 'missing' => esc_html__('The license key was not defined.', 'gravityview'), |
380 | 380 | 'revoked' => esc_html__('This license key has been revoked.', 'gravityview'), |
381 | - 'expired' => sprintf( esc_html__('This license key has expired. %sRenew your license on the GravityView website%s to receive updates and support.', 'gravityview'), '<a href="'. esc_url( $this->get_license_renewal_url( $license_data ) ) .'">', '</a>' ), |
|
382 | - 'capability' => esc_html__( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ), |
|
381 | + 'expired' => sprintf(esc_html__('This license key has expired. %sRenew your license on the GravityView website%s to receive updates and support.', 'gravityview'), '<a href="'.esc_url($this->get_license_renewal_url($license_data)).'">', '</a>'), |
|
382 | + 'capability' => esc_html__('You don\'t have the ability to edit plugin settings.', 'gravityview'), |
|
383 | 383 | |
384 | 384 | 'verifying_license' => esc_html__('Verifying license…', 'gravityview'), |
385 | 385 | 'activate_license' => esc_html__('Activate License', 'gravityview'), |
@@ -387,33 +387,33 @@ discard block |
||
387 | 387 | 'check_license' => esc_html__('Verify License', 'gravityview'), |
388 | 388 | ); |
389 | 389 | |
390 | - if( empty( $status ) ) { |
|
390 | + if (empty($status)) { |
|
391 | 391 | return $strings; |
392 | 392 | } |
393 | 393 | |
394 | - if( isset( $strings[ $status ] ) ) { |
|
395 | - return $strings[ $status ]; |
|
394 | + if (isset($strings[$status])) { |
|
395 | + return $strings[$status]; |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | return NULL; |
399 | 399 | } |
400 | 400 | |
401 | - public function validate_license_key( $value, $field ) { |
|
401 | + public function validate_license_key($value, $field) { |
|
402 | 402 | |
403 | 403 | // No license? No status. |
404 | - if( empty( $value ) ) { |
|
404 | + if (empty($value)) { |
|
405 | 405 | return NULL; |
406 | 406 | } |
407 | 407 | |
408 | 408 | $response = $this->license_call(array( |
409 | - 'license' => $this->Addon->get_app_setting( 'license_key' ), |
|
409 | + 'license' => $this->Addon->get_app_setting('license_key'), |
|
410 | 410 | 'edd_action' => 'check_license', |
411 | 411 | 'field_id' => $field['name'], |
412 | 412 | )); |
413 | 413 | |
414 | - $response = is_string( $response ) ? json_decode( $response, true ) : $response; |
|
414 | + $response = is_string($response) ? json_decode($response, true) : $response; |
|
415 | 415 | |
416 | - switch( $response['license'] ) { |
|
416 | + switch ($response['license']) { |
|
417 | 417 | case 'valid': |
418 | 418 | $return = true; |
419 | 419 | break; |
@@ -225,7 +225,7 @@ |
||
225 | 225 | * Does the if and the comparison match? |
226 | 226 | * @uses GVCommon::matches_operation |
227 | 227 | * |
228 | - * @return boolean True: yep; false: nope |
|
228 | + * @return boolean|null True: yep; false: nope |
|
229 | 229 | */ |
230 | 230 | function set_is_match() { |
231 | 231 | $this->is_match = GVCommon::matches_operation( $this->if, $this->comparison, $this->operation ); |
@@ -5,13 +5,13 @@ discard block |
||
5 | 5 | */ |
6 | 6 | class GVLogic_Shortcode { |
7 | 7 | |
8 | - private static $SUPPORTED_SCALAR_OPERATORS = array( 'is', 'isnot', 'contains', 'starts_with', 'ends_with' ); |
|
8 | + private static $SUPPORTED_SCALAR_OPERATORS = array('is', 'isnot', 'contains', 'starts_with', 'ends_with'); |
|
9 | 9 | |
10 | - private static $SUPPORTED_NUMERIC_OPERATORS = array( 'greater_than', 'less_than' ); |
|
10 | + private static $SUPPORTED_NUMERIC_OPERATORS = array('greater_than', 'less_than'); |
|
11 | 11 | |
12 | - private static $SUPPORTED_ARRAY_OPERATORS = array( 'in', 'not_in', 'isnot', 'contains' ); |
|
12 | + private static $SUPPORTED_ARRAY_OPERATORS = array('in', 'not_in', 'isnot', 'contains'); |
|
13 | 13 | |
14 | - private static $SUPPORTED_CUSTOM_OPERATORS = array( 'equals', 'greater_than_or_is', 'greater_than_or_equals', 'less_than_or_is', 'less_than_or_equals', 'not_contains' ); |
|
14 | + private static $SUPPORTED_CUSTOM_OPERATORS = array('equals', 'greater_than_or_is', 'greater_than_or_equals', 'less_than_or_is', 'less_than_or_equals', 'not_contains'); |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Attributes passed to the shortcode |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public static function get_instance() { |
87 | 87 | |
88 | - if( empty( self::$instance ) ) { |
|
88 | + if (empty(self::$instance)) { |
|
89 | 89 | self::$instance = new self; |
90 | 90 | } |
91 | 91 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @return void |
106 | 106 | */ |
107 | 107 | function add_hooks() { |
108 | - add_shortcode( 'gvlogic', array( $this, 'shortcode' ) ); |
|
108 | + add_shortcode('gvlogic', array($this, 'shortcode')); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return array |
116 | 116 | */ |
117 | - function get_operators( $with_values = false ) { |
|
117 | + function get_operators($with_values = false) { |
|
118 | 118 | |
119 | - $operators = array_merge( self::$SUPPORTED_ARRAY_OPERATORS, self::$SUPPORTED_NUMERIC_OPERATORS, self::$SUPPORTED_SCALAR_OPERATORS, self::$SUPPORTED_CUSTOM_OPERATORS ); |
|
119 | + $operators = array_merge(self::$SUPPORTED_ARRAY_OPERATORS, self::$SUPPORTED_NUMERIC_OPERATORS, self::$SUPPORTED_SCALAR_OPERATORS, self::$SUPPORTED_CUSTOM_OPERATORS); |
|
120 | 120 | |
121 | - if( $with_values ) { |
|
121 | + if ($with_values) { |
|
122 | 122 | $operators_with_values = array(); |
123 | - foreach( $operators as $key ) { |
|
124 | - $operators_with_values[ $key ] = ''; |
|
123 | + foreach ($operators as $key) { |
|
124 | + $operators_with_values[$key] = ''; |
|
125 | 125 | } |
126 | 126 | return $operators_with_values; |
127 | 127 | } else { |
@@ -135,16 +135,16 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return bool True: it's an allowed operation type and was added. False: invalid operation type |
137 | 137 | */ |
138 | - function set_operation( $operation = '' ) { |
|
138 | + function set_operation($operation = '') { |
|
139 | 139 | |
140 | - if( empty( $operation ) ) { |
|
140 | + if (empty($operation)) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | - $operators = $this->get_operators( false ); |
|
144 | + $operators = $this->get_operators(false); |
|
145 | 145 | |
146 | - if( !in_array( $operation, $operators ) ) { |
|
147 | - do_action( 'gravityview_log_debug', __METHOD__ .' Attempted to add invalid operation type.', $operation ); |
|
146 | + if (!in_array($operation, $operators)) { |
|
147 | + do_action('gravityview_log_debug', __METHOD__.' Attempted to add invalid operation type.', $operation); |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | */ |
165 | 165 | function setup_operation_and_comparison() { |
166 | 166 | |
167 | - foreach( $this->atts as $key => $value ) { |
|
167 | + foreach ($this->atts as $key => $value) { |
|
168 | 168 | |
169 | - $valid = $this->set_operation( $key ); |
|
169 | + $valid = $this->set_operation($key); |
|
170 | 170 | |
171 | - if( $valid ) { |
|
171 | + if ($valid) { |
|
172 | 172 | $this->comparison = $value; |
173 | 173 | return true; |
174 | 174 | } |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return string|null |
186 | 186 | */ |
187 | - public function shortcode( $atts = array(), $content = NULL, $shortcode_tag = '' ) { |
|
187 | + public function shortcode($atts = array(), $content = NULL, $shortcode_tag = '') { |
|
188 | 188 | |
189 | 189 | // Don't process except on frontend |
190 | - if ( GravityView_Plugin::is_admin() ) { |
|
190 | + if (GravityView_Plugin::is_admin()) { |
|
191 | 191 | return null; |
192 | 192 | } |
193 | 193 | |
@@ -198,16 +198,16 @@ discard block |
||
198 | 198 | $this->parse_atts(); |
199 | 199 | |
200 | 200 | // We need an "if" |
201 | - if( false === $this->if ) { |
|
202 | - do_action( 'gravityview_log_error', __METHOD__.' $atts->if is empty.', $this->atts ); |
|
201 | + if (false === $this->if) { |
|
202 | + do_action('gravityview_log_error', __METHOD__.' $atts->if is empty.', $this->atts); |
|
203 | 203 | return null; |
204 | 204 | } |
205 | 205 | |
206 | 206 | $setup = $this->setup_operation_and_comparison(); |
207 | 207 | |
208 | 208 | // We need an operation and comparison value |
209 | - if( ! $setup ) { |
|
210 | - do_action( 'gravityview_log_error', __METHOD__.' No valid operators were passed.', $this->atts ); |
|
209 | + if (!$setup) { |
|
210 | + do_action('gravityview_log_error', __METHOD__.' No valid operators were passed.', $this->atts); |
|
211 | 211 | return null; |
212 | 212 | } |
213 | 213 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @return boolean True: yep; false: nope |
229 | 229 | */ |
230 | 230 | function set_is_match() { |
231 | - $this->is_match = GVCommon::matches_operation( $this->if, $this->comparison, $this->operation ); |
|
231 | + $this->is_match = GVCommon::matches_operation($this->if, $this->comparison, $this->operation); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -238,23 +238,23 @@ discard block |
||
238 | 238 | */ |
239 | 239 | function get_output() { |
240 | 240 | |
241 | - if( $this->is_match ) { |
|
241 | + if ($this->is_match) { |
|
242 | 242 | $output = $this->content; |
243 | 243 | } else { |
244 | 244 | $output = $this->else_content; |
245 | 245 | } |
246 | 246 | |
247 | 247 | // Get recursive! |
248 | - $output = do_shortcode( $output ); |
|
248 | + $output = do_shortcode($output); |
|
249 | 249 | |
250 | 250 | /** |
251 | 251 | * @filter `gravityview/gvlogic/output` Modify the [gvlogic] output |
252 | 252 | * @param string $output HTML/text output |
253 | 253 | * @param GVLogic_Shortcode $this This class |
254 | 254 | */ |
255 | - $output = apply_filters('gravityview/gvlogic/output', $output, $this ); |
|
255 | + $output = apply_filters('gravityview/gvlogic/output', $output, $this); |
|
256 | 256 | |
257 | - do_action( 'gravityview_log_debug', __METHOD__ .' Output: ', $output ); |
|
257 | + do_action('gravityview_log_debug', __METHOD__.' Output: ', $output); |
|
258 | 258 | |
259 | 259 | return $output; |
260 | 260 | } |
@@ -268,13 +268,13 @@ discard block |
||
268 | 268 | */ |
269 | 269 | function set_content_and_else_content() { |
270 | 270 | |
271 | - $content = explode( '[else]', $this->passed_content ); |
|
271 | + $content = explode('[else]', $this->passed_content); |
|
272 | 272 | |
273 | 273 | $this->content = $content[0]; |
274 | 274 | |
275 | - $else_attr = isset( $this->atts['else'] ) ? $this->atts['else'] : NULL; |
|
275 | + $else_attr = isset($this->atts['else']) ? $this->atts['else'] : NULL; |
|
276 | 276 | |
277 | - $this->else_content = isset( $content[1] ) ? $content[1] : $else_attr; |
|
277 | + $this->else_content = isset($content[1]) ? $content[1] : $else_attr; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -288,19 +288,19 @@ discard block |
||
288 | 288 | 'else' => false, |
289 | 289 | ); |
290 | 290 | |
291 | - $supported_args = $supported + $this->get_operators( true ); |
|
291 | + $supported_args = $supported + $this->get_operators(true); |
|
292 | 292 | |
293 | 293 | // Whittle down the attributes to only valid pairs |
294 | - $this->atts = shortcode_atts( $supported_args, $this->passed_atts, $this->shortcode ); |
|
294 | + $this->atts = shortcode_atts($supported_args, $this->passed_atts, $this->shortcode); |
|
295 | 295 | |
296 | 296 | // Only keep the passed attributes after making sure that they're valid pairs |
297 | - $this->atts = function_exists( 'array_intersect_key' ) ? array_intersect_key( $this->passed_atts, $this->atts ) : $this->atts; |
|
297 | + $this->atts = function_exists('array_intersect_key') ? array_intersect_key($this->passed_atts, $this->atts) : $this->atts; |
|
298 | 298 | |
299 | 299 | // Strip whitespace if it's not default false |
300 | - $this->if = is_string( $this->atts['if'] ) ? trim( $this->atts['if'] ) : false; |
|
300 | + $this->if = is_string($this->atts['if']) ? trim($this->atts['if']) : false; |
|
301 | 301 | |
302 | 302 | // Make sure the "if" isn't processed in self::setup_operation_and_comparison() |
303 | - unset( $this->atts['if'] ); |
|
303 | + unset($this->atts['if']); |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 |
@@ -211,6 +211,7 @@ |
||
211 | 211 | * @var $view_id |
212 | 212 | * |
213 | 213 | * @see render_handler |
214 | + * @param string $url |
|
214 | 215 | */ |
215 | 216 | private function set_vars( $matches, $attr, $url, $rawattr ) { |
216 | 217 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 1.6 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if (!defined('ABSPATH')) { |
|
14 | 14 | die; |
15 | 15 | } |
16 | 16 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | private function initialize() { |
34 | 34 | |
35 | - add_action( 'init', array( $this, 'register_handler' ) ); |
|
35 | + add_action('init', array($this, 'register_handler')); |
|
36 | 36 | |
37 | 37 | } |
38 | 38 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | static function getInstance() { |
44 | 44 | |
45 | - if( empty( self::$instance ) ) { |
|
45 | + if (empty(self::$instance)) { |
|
46 | 46 | self::$instance = new self; |
47 | 47 | |
48 | 48 | self::$instance->initialize(); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | function register_handler() { |
61 | 61 | |
62 | - wp_embed_register_handler( 'gravityview_entry', $this->get_handler_regex(), array( $this, 'render_handler' ), 20000 ); |
|
62 | + wp_embed_register_handler('gravityview_entry', $this->get_handler_regex(), array($this, 'render_handler'), 20000); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -80,16 +80,16 @@ discard block |
||
80 | 80 | * @filter `gravityview_slug` Modify the url part for a View. [Read the doc](http://docs.gravityview.co/article/62-changing-the-view-slug) |
81 | 81 | * @param string $rewrite_slug The slug shown in the URL |
82 | 82 | */ |
83 | - $rewrite_slug = apply_filters( 'gravityview_slug', 'view' ); |
|
83 | + $rewrite_slug = apply_filters('gravityview_slug', 'view'); |
|
84 | 84 | |
85 | 85 | // Only support embeds for current site |
86 | - $prefix = trailingslashit( home_url() ); |
|
86 | + $prefix = trailingslashit(home_url()); |
|
87 | 87 | |
88 | 88 | // Using permalinks |
89 | - $using_permalinks = $prefix . "(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$"; |
|
89 | + $using_permalinks = $prefix."(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$"; |
|
90 | 90 | |
91 | 91 | // Not using permalinks |
92 | - $not_using_permalinks = $prefix . "(?:index.php)?\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$"; |
|
92 | + $not_using_permalinks = $prefix."(?:index.php)?\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$"; |
|
93 | 93 | |
94 | 94 | // Catch either |
95 | 95 | $match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})"; |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | * @param string $slug The name of a post, used as backup way of checking for post ID |
110 | 110 | * @return int 0 if not found; int of URL post ID otherwise |
111 | 111 | */ |
112 | - private function get_postid_from_url_and_slug( $url = '', $slug = '' ) { |
|
112 | + private function get_postid_from_url_and_slug($url = '', $slug = '') { |
|
113 | 113 | |
114 | - $post_id = url_to_postid( $url ); |
|
114 | + $post_id = url_to_postid($url); |
|
115 | 115 | |
116 | - if( empty( $post_id ) ) { |
|
116 | + if (empty($post_id)) { |
|
117 | 117 | |
118 | 118 | $args = array( |
119 | 119 | 'post_status' => 'publish', |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | 'post_type' => array('any', 'gravityview'), |
122 | 122 | ); |
123 | 123 | |
124 | - $posts = get_posts( $args ); |
|
124 | + $posts = get_posts($args); |
|
125 | 125 | |
126 | - if( !empty( $posts ) ) { |
|
126 | + if (!empty($posts)) { |
|
127 | 127 | $post_id = $posts[0]->ID; |
128 | 128 | } |
129 | 129 | } |
@@ -154,20 +154,20 @@ discard block |
||
154 | 154 | * @param array $rawattr The original unmodified attributes. |
155 | 155 | * @return string The embed HTML. |
156 | 156 | */ |
157 | - public function render_handler( $matches, $attr, $url, $rawattr ) { |
|
157 | + public function render_handler($matches, $attr, $url, $rawattr) { |
|
158 | 158 | |
159 | 159 | // If not using permalinks, re-assign values for matching groups |
160 | - if( !empty( $matches['entry_slug2'] ) ) { |
|
160 | + if (!empty($matches['entry_slug2'])) { |
|
161 | 161 | $matches['is_cpt'] = $matches['is_cpt2']; |
162 | 162 | $matches['slug'] = $matches['slug2']; |
163 | 163 | $matches['entry_slug'] = $matches['entry_slug2']; |
164 | - unset( $matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2'] ); |
|
164 | + unset($matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2']); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // No Entry was found |
168 | - if( empty( $matches['entry_slug'] ) ) { |
|
168 | + if (empty($matches['entry_slug'])) { |
|
169 | 169 | |
170 | - do_action('gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches ); |
|
170 | + do_action('gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches); |
|
171 | 171 | |
172 | 172 | return ''; |
173 | 173 | } |
@@ -175,17 +175,17 @@ discard block |
||
175 | 175 | $return = ''; |
176 | 176 | |
177 | 177 | // Setup the data used |
178 | - $this->set_vars( $matches, $attr, $url, $rawattr ); |
|
178 | + $this->set_vars($matches, $attr, $url, $rawattr); |
|
179 | 179 | |
180 | - if( is_admin() && !$this->is_full_oembed_preview ) { |
|
181 | - $return = $this->render_admin( $matches, $attr, $url, $rawattr ); |
|
180 | + if (is_admin() && !$this->is_full_oembed_preview) { |
|
181 | + $return = $this->render_admin($matches, $attr, $url, $rawattr); |
|
182 | 182 | } else { |
183 | 183 | |
184 | - if( $this->is_full_oembed_preview ) { |
|
184 | + if ($this->is_full_oembed_preview) { |
|
185 | 185 | $return .= $this->generate_preview_notice(); |
186 | 186 | } |
187 | 187 | |
188 | - $return .= $this->render_frontend( $matches, $attr, $url, $rawattr ); |
|
188 | + $return .= $this->render_frontend($matches, $attr, $url, $rawattr); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | return $return; |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | */ |
200 | 200 | private function generate_preview_notice() { |
201 | 201 | $floaty = GravityView_Admin::get_floaty(); |
202 | - $title = esc_html__( 'This will look better when it is embedded.', 'gravityview' ); |
|
202 | + $title = esc_html__('This will look better when it is embedded.', 'gravityview'); |
|
203 | 203 | $message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview'); |
204 | - return '<div class="updated notice">'. $floaty. '<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>'; |
|
204 | + return '<div class="updated notice">'.$floaty.'<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>'; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -212,18 +212,18 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @see render_handler |
214 | 214 | */ |
215 | - private function set_vars( $matches, $attr, $url, $rawattr ) { |
|
215 | + private function set_vars($matches, $attr, $url, $rawattr) { |
|
216 | 216 | |
217 | 217 | $this->entry_id = $matches['entry_slug']; |
218 | 218 | |
219 | - $post_id = $this->get_postid_from_url_and_slug( $url, $matches['slug'] ); |
|
219 | + $post_id = $this->get_postid_from_url_and_slug($url, $matches['slug']); |
|
220 | 220 | |
221 | 221 | // The URL didn't have the View Custom Post Type structure. |
222 | - if( empty( $matches['is_cpt'] ) || $matches['is_cpt'] !== 'gravityview' ) { |
|
222 | + if (empty($matches['is_cpt']) || $matches['is_cpt'] !== 'gravityview') { |
|
223 | 223 | |
224 | - do_action('gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches ); |
|
224 | + do_action('gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches); |
|
225 | 225 | |
226 | - $this->view_id = GravityView_View_Data::getInstance()->maybe_get_view_id( $post_id ); |
|
226 | + $this->view_id = GravityView_View_Data::getInstance()->maybe_get_view_id($post_id); |
|
227 | 227 | |
228 | 228 | } else { |
229 | 229 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | // The inline content has $_POST['type'] set to "embed", while the "Add Media" modal doesn't set that. |
235 | - $this->is_full_oembed_preview = ( isset( $_POST['action'] ) && $_POST['action'] === 'parse-embed' && !isset( $_POST['type'] ) ); |
|
235 | + $this->is_full_oembed_preview = (isset($_POST['action']) && $_POST['action'] === 'parse-embed' && !isset($_POST['type'])); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -244,15 +244,15 @@ discard block |
||
244 | 244 | * @param array $rawattr The original unmodified attributes. |
245 | 245 | * @return string The embed HTML. |
246 | 246 | */ |
247 | - private function render_admin( $matches, $attr, $url, $rawattr ) { |
|
247 | + private function render_admin($matches, $attr, $url, $rawattr) { |
|
248 | 248 | global $wp_version; |
249 | 249 | |
250 | 250 | // Floaty the astronaut |
251 | 251 | $image = GravityView_Admin::get_floaty(); |
252 | 252 | |
253 | - $embed_heading = sprintf( esc_html__('Embed Entry %d', 'gravityview'), $this->entry_id ); |
|
253 | + $embed_heading = sprintf(esc_html__('Embed Entry %d', 'gravityview'), $this->entry_id); |
|
254 | 254 | |
255 | - $embed_text = sprintf( esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $this->view_id ); |
|
255 | + $embed_text = sprintf(esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $this->view_id); |
|
256 | 256 | |
257 | 257 | return ' |
258 | 258 | <div class="loading-placeholder" style="background-color:#e6f0f5;"> |
@@ -268,21 +268,21 @@ discard block |
||
268 | 268 | private function generate_entry_output() { |
269 | 269 | |
270 | 270 | // Tell get_gravityview() to display a single entry |
271 | - add_filter( 'gravityview/is_single_entry', array( $this, 'set_single_entry_id' ) ); |
|
271 | + add_filter('gravityview/is_single_entry', array($this, 'set_single_entry_id')); |
|
272 | 272 | |
273 | 273 | ob_start(); |
274 | 274 | |
275 | 275 | // Print the entry as configured in View |
276 | - the_gravityview( $this->view_id ); |
|
276 | + the_gravityview($this->view_id); |
|
277 | 277 | |
278 | 278 | $view_html = ob_get_clean(); |
279 | 279 | |
280 | 280 | // Clean up the filter |
281 | - remove_filter( 'gravityview/is_single_entry', array( $this, 'set_single_entry_id' ) ); |
|
281 | + remove_filter('gravityview/is_single_entry', array($this, 'set_single_entry_id')); |
|
282 | 282 | |
283 | 283 | // Strip the new lines that are generated--when editing an entry in particular, scripts are printed that |
284 | 284 | // then are passed through wpautop() and everything looks terrible. |
285 | - $view_html = str_replace( "\n", ' ', $view_html ); |
|
285 | + $view_html = str_replace("\n", ' ', $view_html); |
|
286 | 286 | |
287 | 287 | return $view_html; |
288 | 288 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return int The current entry ID |
298 | 298 | */ |
299 | - public function set_single_entry_id( $is_single_entry = false ) { |
|
299 | + public function set_single_entry_id($is_single_entry = false) { |
|
300 | 300 | |
301 | 301 | return $this->entry_id; |
302 | 302 | } |
@@ -310,17 +310,17 @@ discard block |
||
310 | 310 | * @param array $rawattr The original unmodified attributes. |
311 | 311 | * @return string The embed HTML. |
312 | 312 | */ |
313 | - private function render_frontend( $matches, $attr, $url, $rawattr ) { |
|
313 | + private function render_frontend($matches, $attr, $url, $rawattr) { |
|
314 | 314 | |
315 | 315 | // If it's already been parsed, don't re-output it. |
316 | - if( !empty( $this->output[ $this->entry_id ] ) ) { |
|
317 | - return $this->output[ $this->entry_id ]; |
|
316 | + if (!empty($this->output[$this->entry_id])) { |
|
317 | + return $this->output[$this->entry_id]; |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | $entry_output = $this->generate_entry_output(); |
321 | 321 | |
322 | 322 | // Wrap a container div around the output to allow for custom styling |
323 | - $output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-'.$this->entry_id.'">%s</div>', $entry_output ); |
|
323 | + $output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-'.$this->entry_id.'">%s</div>', $entry_output); |
|
324 | 324 | |
325 | 325 | /** |
326 | 326 | * @filter `gravityview/oembed/entry` Filter the output of the oEmbed entry embed |
@@ -333,13 +333,13 @@ discard block |
||
333 | 333 | * @var string $url The original URL that was matched by the regex. \n |
334 | 334 | * @var array $rawattr The original unmodified attributes. |
335 | 335 | */ |
336 | - $output = apply_filters('gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) ); |
|
336 | + $output = apply_filters('gravityview/oembed/entry', $output, $this, compact($entry_output, $matches, $attr, $url, $rawattr)); |
|
337 | 337 | |
338 | - unset( $entry_output ); |
|
338 | + unset($entry_output); |
|
339 | 339 | |
340 | - $this->output[ $this->entry_id ] = $output; |
|
340 | + $this->output[$this->entry_id] = $output; |
|
341 | 341 | |
342 | - return $this->output[ $this->entry_id ]; |
|
342 | + return $this->output[$this->entry_id]; |
|
343 | 343 | |
344 | 344 | } |
345 | 345 |
@@ -301,6 +301,7 @@ |
||
301 | 301 | * Make protected public |
302 | 302 | * @inheritDoc |
303 | 303 | * @access public |
304 | + * @param string $setting_name |
|
304 | 305 | */ |
305 | 306 | public function get_app_setting( $setting_name ) { |
306 | 307 |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | type="' . $field['type'] . '" |
419 | 419 | name="' . esc_attr( $name ) . '" |
420 | 420 | value="' . $value . '" ' . |
421 | - implode( ' ', $attributes ) . |
|
422 | - ' />'; |
|
421 | + implode( ' ', $attributes ) . |
|
422 | + ' />'; |
|
423 | 423 | |
424 | 424 | if ( $echo ) { |
425 | 425 | echo $html; |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | array( |
649 | 649 | 'label' => _x( 'Permanently Delete', 'Setting: what to do when uninstalling plugin', 'gravityview' ), |
650 | 650 | 'value' => 'delete', |
651 | - 'tooltip' => sprintf( '<h6>%s</h6><p><span class="howto">%s</span></p><p>%s</p>', __( 'Delete all GravityView content and settings', 'gravityview' ), __( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' ), __( 'When GravityView is uninstalled and deleted, delete all Views, GravityView entry approvals, GravityView-generated entry notes (including approval and entry creator changes), and GravityView plugin settings. No Gravity Forms data will be touched.', 'gravityview' ) ), |
|
651 | + 'tooltip' => sprintf( '<h6>%s</h6><p><span class="howto">%s</span></p><p>%s</p>', __( 'Delete all GravityView content and settings', 'gravityview' ), __( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' ), __( 'When GravityView is uninstalled and deleted, delete all Views, GravityView entry approvals, GravityView-generated entry notes (including approval and entry creator changes), and GravityView plugin settings. No Gravity Forms data will be touched.', 'gravityview' ) ), |
|
652 | 652 | ), |
653 | 653 | ), |
654 | 654 | 'description' => sprintf( __( 'Should GravityView content and entry approval status be removed from the site when the GravityView plugin is deleted?', 'gravityview' ), __( 'Permanently Delete', 'gravityview' ) ), |
@@ -674,36 +674,36 @@ discard block |
||
674 | 674 | } |
675 | 675 | |
676 | 676 | |
677 | - $sections = array( |
|
678 | - array( |
|
679 | - 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
680 | - 'fields' => $fields, |
|
681 | - ) |
|
682 | - ); |
|
677 | + $sections = array( |
|
678 | + array( |
|
679 | + 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
680 | + 'fields' => $fields, |
|
681 | + ) |
|
682 | + ); |
|
683 | 683 | |
684 | - // custom 'update settings' button |
|
685 | - $button = array( |
|
686 | - 'class' => 'button button-primary button-hero', |
|
687 | - 'type' => 'save', |
|
688 | - ); |
|
684 | + // custom 'update settings' button |
|
685 | + $button = array( |
|
686 | + 'class' => 'button button-primary button-hero', |
|
687 | + 'type' => 'save', |
|
688 | + ); |
|
689 | 689 | |
690 | 690 | if( $disabled_attribute ) { |
691 | 691 | $button['disabled'] = $disabled_attribute; |
692 | 692 | } |
693 | 693 | |
694 | 694 | |
695 | - /** |
|
696 | - * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page |
|
697 | - * Extensions can tap in here to insert their own section and settings. |
|
698 | - * <code> |
|
699 | - * $sections[] = array( |
|
700 | - * 'title' => __( 'GravityView My Extension Settings', 'gravityview' ), |
|
701 | - * 'fields' => $settings, |
|
702 | - * ); |
|
703 | - * </code> |
|
704 | - * @param array $extension_settings Empty array, ready for extension settings! |
|
705 | - */ |
|
706 | - $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() ); |
|
695 | + /** |
|
696 | + * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page |
|
697 | + * Extensions can tap in here to insert their own section and settings. |
|
698 | + * <code> |
|
699 | + * $sections[] = array( |
|
700 | + * 'title' => __( 'GravityView My Extension Settings', 'gravityview' ), |
|
701 | + * 'fields' => $settings, |
|
702 | + * ); |
|
703 | + * </code> |
|
704 | + * @param array $extension_settings Empty array, ready for extension settings! |
|
705 | + */ |
|
706 | + $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() ); |
|
707 | 707 | |
708 | 708 | // If there are extensions, add a section for them |
709 | 709 | if ( ! empty( $extension_sections ) ) { |
@@ -716,13 +716,13 @@ discard block |
||
716 | 716 | } |
717 | 717 | } |
718 | 718 | |
719 | - $k = count( $extension_sections ) - 1 ; |
|
720 | - $extension_sections[ $k ]['fields'][] = $button; |
|
719 | + $k = count( $extension_sections ) - 1 ; |
|
720 | + $extension_sections[ $k ]['fields'][] = $button; |
|
721 | 721 | $sections = array_merge( $sections, $extension_sections ); |
722 | 722 | } else { |
723 | - // add the 'update settings' button to the general section |
|
724 | - $sections[0]['fields'][] = $button; |
|
725 | - } |
|
723 | + // add the 'update settings' button to the general section |
|
724 | + $sections[0]['fields'][] = $button; |
|
725 | + } |
|
726 | 726 | |
727 | 727 | return $sections; |
728 | 728 | } |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @param string $prevent_multiple_instances |
71 | 71 | */ |
72 | - public function __construct( $prevent_multiple_instances = '' ) { |
|
72 | + public function __construct($prevent_multiple_instances = '') { |
|
73 | 73 | |
74 | - if( $prevent_multiple_instances === 'get_instance' ) { |
|
74 | + if ($prevent_multiple_instances === 'get_instance') { |
|
75 | 75 | return parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public static function get_instance() { |
85 | 85 | |
86 | - if( empty( self::$instance ) ) { |
|
87 | - self::$instance = new self( 'get_instance' ); |
|
86 | + if (empty(self::$instance)) { |
|
87 | + self::$instance = new self('get_instance'); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | return self::$instance; |
@@ -100,21 +100,21 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return bool |
102 | 102 | */ |
103 | - public function current_user_can_any( $caps ) { |
|
103 | + public function current_user_can_any($caps) { |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Prevent Gravity Forms from showing the uninstall tab on the settings page |
107 | 107 | * @hack |
108 | 108 | */ |
109 | - if( $caps === $this->_capabilities_uninstall ) { |
|
109 | + if ($caps === $this->_capabilities_uninstall) { |
|
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | - if( empty( $caps ) ) { |
|
114 | - $caps = array( 'gravityview_full_access' ); |
|
113 | + if (empty($caps)) { |
|
114 | + $caps = array('gravityview_full_access'); |
|
115 | 115 | } |
116 | 116 | |
117 | - return GVCommon::has_cap( $caps ); |
|
117 | + return GVCommon::has_cap($caps); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | |
131 | 131 | $this->license_key_notice(); |
132 | 132 | |
133 | - add_filter( 'gform_addon_app_settings_menu_gravityview', array( $this, 'modify_app_settings_menu_title' ) ); |
|
133 | + add_filter('gform_addon_app_settings_menu_gravityview', array($this, 'modify_app_settings_menu_title')); |
|
134 | 134 | |
135 | 135 | /** @since 1.7.6 */ |
136 | - add_action('network_admin_menu', array( $this, 'add_network_menu' ) ); |
|
136 | + add_action('network_admin_menu', array($this, 'add_network_menu')); |
|
137 | 137 | |
138 | 138 | parent::init_admin(); |
139 | 139 | } |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return array |
147 | 147 | */ |
148 | - public function modify_app_settings_menu_title( $setting_tabs ) { |
|
148 | + public function modify_app_settings_menu_title($setting_tabs) { |
|
149 | 149 | |
150 | - $setting_tabs[0]['label'] = __( 'GravityView Settings', 'gravityview'); |
|
150 | + $setting_tabs[0]['label'] = __('GravityView Settings', 'gravityview'); |
|
151 | 151 | |
152 | 152 | return $setting_tabs; |
153 | 153 | } |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | */ |
165 | 165 | private function _load_license_handler() { |
166 | 166 | |
167 | - if( !empty( $this->License_Handler ) ) { |
|
167 | + if (!empty($this->License_Handler)) { |
|
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | - require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php'); |
|
171 | + require_once(GRAVITYVIEW_DIR.'includes/class-gv-license-handler.php'); |
|
172 | 172 | |
173 | - $this->License_Handler = GV_License_Handler::get_instance( $this ); |
|
173 | + $this->License_Handler = GV_License_Handler::get_instance($this); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -180,18 +180,18 @@ discard block |
||
180 | 180 | function license_key_notice() { |
181 | 181 | |
182 | 182 | // Show license notice on all GV pages, except for settings page |
183 | - if( gravityview_is_admin_page( '', 'settings' ) ) { |
|
183 | + if (gravityview_is_admin_page('', 'settings')) { |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | 187 | $license_status = self::getSetting('license_key_status'); |
188 | 188 | $license_id = self::getSetting('license_key'); |
189 | - $license_id = empty( $license_id ) ? 'license' : $license_id; |
|
189 | + $license_id = empty($license_id) ? 'license' : $license_id; |
|
190 | 190 | |
191 | 191 | $message = esc_html__('Your GravityView license %s. This means you’re missing out on updates and support! %sActivate your license%s or %sget a license here%s.', 'gravityview'); |
192 | 192 | $title = __('Inactive License', 'gravityview'); |
193 | 193 | $status = ''; |
194 | - switch ( $license_status ) { |
|
194 | + switch ($license_status) { |
|
195 | 195 | case 'invalid': |
196 | 196 | $title = __('Invalid License', 'gravityview'); |
197 | 197 | $status = __('is invalid', 'gravityview'); |
@@ -208,13 +208,13 @@ discard block |
||
208 | 208 | break; |
209 | 209 | } |
210 | 210 | $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice'; |
211 | - $message = sprintf( $message, $status, "\n\n".'<a href="'.admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ).'" class="button button-primary">', '</a>', '<a href="'.esc_url( $url ).'" class="button button-secondary">', '</a>' ); |
|
212 | - if( !empty( $status ) ) { |
|
213 | - GravityView_Admin_Notices::add_notice( array( |
|
211 | + $message = sprintf($message, $status, "\n\n".'<a href="'.admin_url('edit.php?post_type=gravityview&page=gravityview_settings').'" class="button button-primary">', '</a>', '<a href="'.esc_url($url).'" class="button button-secondary">', '</a>'); |
|
212 | + if (!empty($status)) { |
|
213 | + GravityView_Admin_Notices::add_notice(array( |
|
214 | 214 | 'message' => $message, |
215 | 215 | 'class' => 'updated', |
216 | 216 | 'title' => $title, |
217 | - 'dismiss' => sha1( $license_status.'_'.$license_id ), |
|
217 | + 'dismiss' => sha1($license_status.'_'.$license_id), |
|
218 | 218 | )); |
219 | 219 | } |
220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | |
230 | 230 | $styles[] = array( |
231 | 231 | 'handle' => 'gravityview_settings', |
232 | - 'src' => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ), |
|
232 | + 'src' => plugins_url('assets/css/admin-settings.css', GRAVITYVIEW_FILE), |
|
233 | 233 | 'version' => GravityView_Plugin::version, |
234 | 234 | "deps" => array( |
235 | 235 | 'gaddon_form_settings_css' |
236 | 236 | ), |
237 | 237 | 'enqueue' => array( |
238 | - array( 'admin_page' => array( |
|
238 | + array('admin_page' => array( |
|
239 | 239 | 'app_settings' |
240 | - ) ), |
|
240 | + )), |
|
241 | 241 | ) |
242 | 242 | ); |
243 | 243 | |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | * @return void |
251 | 251 | */ |
252 | 252 | public function add_network_menu() { |
253 | - if( GravityView_Plugin::is_network_activated() ) { |
|
254 | - add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' ); |
|
253 | + if (GravityView_Plugin::is_network_activated()) { |
|
254 | + add_menu_page(__('Settings', 'gravityview'), __('GravityView', 'gravityview'), $this->_capabilities_app_settings, "{$this->_slug}_settings", array($this, 'app_tab_page'), 'none'); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
@@ -267,17 +267,17 @@ discard block |
||
267 | 267 | * If multisite and not network admin, we don't want the settings to show. |
268 | 268 | * @since 1.7.6 |
269 | 269 | */ |
270 | - $show_submenu = !is_multisite() || is_main_site() || !GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); |
|
270 | + $show_submenu = !is_multisite() || is_main_site() || !GravityView_Plugin::is_network_activated() || (is_network_admin() && GravityView_Plugin::is_network_activated()); |
|
271 | 271 | |
272 | 272 | /** |
273 | 273 | * Override whether to show the Settings menu on a per-blog basis. |
274 | 274 | * @since 1.7.6 |
275 | 275 | * @param bool $hide_if_network_activated Default: true |
276 | 276 | */ |
277 | - $show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu ); |
|
277 | + $show_submenu = apply_filters('gravityview/show-settings-menu', $show_submenu); |
|
278 | 278 | |
279 | - if( $show_submenu ) { |
|
280 | - add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) ); |
|
279 | + if ($show_submenu) { |
|
280 | + add_submenu_page('edit.php?post_type=gravityview', __('Settings', 'gravityview'), __('Settings', 'gravityview'), $this->_capabilities_app_settings, $this->_slug.'_settings', array($this, 'app_tab_page')); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
@@ -302,20 +302,20 @@ discard block |
||
302 | 302 | * @inheritDoc |
303 | 303 | * @access public |
304 | 304 | */ |
305 | - public function get_app_setting( $setting_name ) { |
|
305 | + public function get_app_setting($setting_name) { |
|
306 | 306 | |
307 | 307 | /** |
308 | 308 | * Backward compatibility with Redux |
309 | 309 | */ |
310 | - if( $setting_name === 'license' ) { |
|
310 | + if ($setting_name === 'license') { |
|
311 | 311 | return array( |
312 | - 'license' => parent::get_app_setting( 'license_key' ), |
|
313 | - 'status' => parent::get_app_setting( 'license_key_status' ), |
|
314 | - 'response' => parent::get_app_setting( 'license_key_response' ), |
|
312 | + 'license' => parent::get_app_setting('license_key'), |
|
313 | + 'status' => parent::get_app_setting('license_key_status'), |
|
314 | + 'response' => parent::get_app_setting('license_key_response'), |
|
315 | 315 | ); |
316 | 316 | } |
317 | 317 | |
318 | - return parent::get_app_setting( $setting_name ); |
|
318 | + return parent::get_app_setting($setting_name); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @return array |
331 | 331 | */ |
332 | 332 | public function get_app_settings() { |
333 | - return get_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $this->get_default_settings() ); |
|
333 | + return get_option('gravityformsaddon_'.$this->_slug.'_app_settings', $this->get_default_settings()); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | * |
344 | 344 | * @return boolean False if value was not updated and true if value was updated. |
345 | 345 | */ |
346 | - public function update_app_settings( $settings ) { |
|
347 | - return update_option( 'gravityformsaddon_' . $this->_slug . '_app_settings', $settings ); |
|
346 | + public function update_app_settings($settings) { |
|
347 | + return update_option('gravityformsaddon_'.$this->_slug.'_app_settings', $settings); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -352,8 +352,8 @@ discard block |
||
352 | 352 | * @inheritDoc |
353 | 353 | * @access public |
354 | 354 | */ |
355 | - public function set_field_error( $field, $error_message = '' ) { |
|
356 | - parent::set_field_error( $field, $error_message ); |
|
355 | + public function set_field_error($field, $error_message = '') { |
|
356 | + parent::set_field_error($field, $error_message); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -363,15 +363,15 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @return string |
365 | 365 | */ |
366 | - protected function settings_edd_license( $field, $echo = true ) { |
|
366 | + protected function settings_edd_license($field, $echo = true) { |
|
367 | 367 | |
368 | - $text = self::settings_text( $field, false ); |
|
368 | + $text = self::settings_text($field, false); |
|
369 | 369 | |
370 | - $activation = $this->License_Handler->settings_edd_license_activation( $field, false ); |
|
370 | + $activation = $this->License_Handler->settings_edd_license_activation($field, false); |
|
371 | 371 | |
372 | - $return = $text . $activation; |
|
372 | + $return = $text.$activation; |
|
373 | 373 | |
374 | - if( $echo ) { |
|
374 | + if ($echo) { |
|
375 | 375 | echo $return; |
376 | 376 | } |
377 | 377 | |
@@ -396,32 +396,32 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @return string The HTML |
398 | 398 | */ |
399 | - public function settings_submit( $field, $echo = true ) { |
|
399 | + public function settings_submit($field, $echo = true) { |
|
400 | 400 | |
401 | - $field['type'] = ( isset($field['type']) && in_array( $field['type'], array('submit','reset','button') ) ) ? $field['type'] : 'submit'; |
|
401 | + $field['type'] = (isset($field['type']) && in_array($field['type'], array('submit', 'reset', 'button'))) ? $field['type'] : 'submit'; |
|
402 | 402 | |
403 | - $attributes = $this->get_field_attributes( $field ); |
|
404 | - $default_value = rgar( $field, 'value' ) ? rgar( $field, 'value' ) : rgar( $field, 'default_value' ); |
|
405 | - $value = $this->get_setting( $field['name'], $default_value ); |
|
403 | + $attributes = $this->get_field_attributes($field); |
|
404 | + $default_value = rgar($field, 'value') ? rgar($field, 'value') : rgar($field, 'default_value'); |
|
405 | + $value = $this->get_setting($field['name'], $default_value); |
|
406 | 406 | |
407 | 407 | |
408 | - $attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton'; |
|
409 | - $name = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_'.$field['name']; |
|
408 | + $attributes['class'] = isset($attributes['class']) ? esc_attr($attributes['class']) : 'button-primary gfbutton'; |
|
409 | + $name = ($field['name'] === 'gform-settings-save') ? $field['name'] : '_gaddon_setting_'.$field['name']; |
|
410 | 410 | |
411 | - if ( empty( $value ) ) { |
|
412 | - $value = __( 'Update Settings', 'gravityview' ); |
|
411 | + if (empty($value)) { |
|
412 | + $value = __('Update Settings', 'gravityview'); |
|
413 | 413 | } |
414 | 414 | |
415 | - $attributes = $this->get_field_attributes( $field ); |
|
415 | + $attributes = $this->get_field_attributes($field); |
|
416 | 416 | |
417 | 417 | $html = '<input |
418 | - type="' . $field['type'] . '" |
|
419 | - name="' . esc_attr( $name ) . '" |
|
420 | - value="' . $value . '" ' . |
|
421 | - implode( ' ', $attributes ) . |
|
418 | + type="' . $field['type'].'" |
|
419 | + name="' . esc_attr($name).'" |
|
420 | + value="' . $value.'" '. |
|
421 | + implode(' ', $attributes). |
|
422 | 422 | ' />'; |
423 | 423 | |
424 | - if ( $echo ) { |
|
424 | + if ($echo) { |
|
425 | 425 | echo $html; |
426 | 426 | } |
427 | 427 | |
@@ -436,17 +436,17 @@ discard block |
||
436 | 436 | * |
437 | 437 | * @return string |
438 | 438 | */ |
439 | - public function settings_save( $field, $echo = true ) { |
|
439 | + public function settings_save($field, $echo = true) { |
|
440 | 440 | $field['type'] = 'submit'; |
441 | 441 | $field['name'] = 'gform-settings-save'; |
442 | - $field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton'; |
|
442 | + $field['class'] = isset($field['class']) ? $field['class'] : 'button-primary gfbutton'; |
|
443 | 443 | |
444 | - if ( ! rgar( $field, 'value' ) ) |
|
445 | - $field['value'] = __( 'Update Settings', 'gravityview' ); |
|
444 | + if (!rgar($field, 'value')) |
|
445 | + $field['value'] = __('Update Settings', 'gravityview'); |
|
446 | 446 | |
447 | - $output = $this->settings_submit( $field, false ); |
|
447 | + $output = $this->settings_submit($field, false); |
|
448 | 448 | |
449 | - if( $echo ) { |
|
449 | + if ($echo) { |
|
450 | 450 | echo $output; |
451 | 451 | } |
452 | 452 | |
@@ -458,22 +458,22 @@ discard block |
||
458 | 458 | * @inheritDoc |
459 | 459 | * @param $field array |
460 | 460 | */ |
461 | - public function single_setting_label( $field ) { |
|
461 | + public function single_setting_label($field) { |
|
462 | 462 | |
463 | 463 | echo $field['label']; |
464 | 464 | |
465 | 465 | |
466 | - if ( isset( $field['tooltip'] ) ) { |
|
467 | - echo ' ' . gform_tooltip( $field['tooltip'], rgar( $field, 'tooltip_class' ), true ); |
|
466 | + if (isset($field['tooltip'])) { |
|
467 | + echo ' '.gform_tooltip($field['tooltip'], rgar($field, 'tooltip_class'), true); |
|
468 | 468 | } |
469 | 469 | |
470 | - if ( rgar( $field, 'required' ) ) { |
|
471 | - echo ' ' . $this->get_required_indicator( $field ); |
|
470 | + if (rgar($field, 'required')) { |
|
471 | + echo ' '.$this->get_required_indicator($field); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | // Added by GravityView |
475 | - if ( isset( $field['description'] ) ) { |
|
476 | - echo '<span class="description">'. $field['description'] .'</span>'; |
|
475 | + if (isset($field['description'])) { |
|
476 | + echo '<span class="description">'.$field['description'].'</span>'; |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | } |
@@ -489,10 +489,10 @@ discard block |
||
489 | 489 | |
490 | 490 | $defaults = array( |
491 | 491 | // Set the default license in wp-config.php |
492 | - 'license_key' => defined( 'GRAVITYVIEW_LICENSE_KEY' ) ? GRAVITYVIEW_LICENSE_KEY : '', |
|
492 | + 'license_key' => defined('GRAVITYVIEW_LICENSE_KEY') ? GRAVITYVIEW_LICENSE_KEY : '', |
|
493 | 493 | 'license_key_response' => '', |
494 | 494 | 'license_key_status' => '', |
495 | - 'support-email' => get_bloginfo( 'admin_email' ), |
|
495 | + 'support-email' => get_bloginfo('admin_email'), |
|
496 | 496 | 'no-conflict-mode' => '0', |
497 | 497 | 'support_port' => '1', |
498 | 498 | 'delete-on-uninstall' => '0', |
@@ -510,10 +510,10 @@ discard block |
||
510 | 510 | */ |
511 | 511 | public function maybe_save_app_settings() { |
512 | 512 | |
513 | - if ( $this->is_save_postback() ) { |
|
514 | - if ( ! GVCommon::has_cap( 'gravityview_edit_settings' ) ) { |
|
513 | + if ($this->is_save_postback()) { |
|
514 | + if (!GVCommon::has_cap('gravityview_edit_settings')) { |
|
515 | 515 | $_POST = array(); // If you don't reset the $_POST array, it *looks* like the settings were changed, but they weren't |
516 | - GFCommon::add_error_message( __( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ) ); |
|
516 | + GFCommon::add_error_message(__('You don\'t have the ability to edit plugin settings.', 'gravityview')); |
|
517 | 517 | return; |
518 | 518 | } |
519 | 519 | } |
@@ -532,10 +532,10 @@ discard block |
||
532 | 532 | |
533 | 533 | // If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response), |
534 | 534 | // then we assume it's changed. If it's changed, unset the status and the previous response. |
535 | - if( isset( $posted_settings['license_key'] ) && isset( $posted_settings['license_key_response']['license_key'] ) && $posted_settings['license_key'] !== $posted_settings['license_key_response']['license_key'] ) { |
|
536 | - unset( $posted_settings['license_key_response'] ); |
|
537 | - unset( $posted_settings['license_key_status'] ); |
|
538 | - GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); |
|
535 | + if (isset($posted_settings['license_key']) && isset($posted_settings['license_key_response']['license_key']) && $posted_settings['license_key'] !== $posted_settings['license_key_response']['license_key']) { |
|
536 | + unset($posted_settings['license_key_response']); |
|
537 | + unset($posted_settings['license_key_status']); |
|
538 | + GFCommon::add_error_message(__('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview')); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | return $posted_settings; |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * |
550 | 550 | * @return string - Returns markup of the required indicator symbol |
551 | 551 | */ |
552 | - public function get_required_indicator( $field ) { |
|
553 | - return '<span class="required" title="' . esc_attr__( 'Required', 'gravityview' ) . '">*</span>'; |
|
552 | + public function get_required_indicator($field) { |
|
553 | + return '<span class="required" title="'.esc_attr__('Required', 'gravityview').'">*</span>'; |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -561,18 +561,18 @@ discard block |
||
561 | 561 | |
562 | 562 | $default_settings = $this->get_default_settings(); |
563 | 563 | |
564 | - $disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled'; |
|
564 | + $disabled_attribute = GVCommon::has_cap('gravityview_edit_settings') ? false : 'disabled'; |
|
565 | 565 | |
566 | - $fields = apply_filters( 'gravityview_settings_fields', array( |
|
566 | + $fields = apply_filters('gravityview_settings_fields', array( |
|
567 | 567 | array( |
568 | 568 | 'name' => 'license_key', |
569 | 569 | 'required' => true, |
570 | - 'label' => __( 'License Key', 'gravityview' ), |
|
571 | - 'description' => __( 'Enter the license key that was sent to you on purchase. This enables plugin updates & support.', 'gravityview' ), |
|
570 | + 'label' => __('License Key', 'gravityview'), |
|
571 | + 'description' => __('Enter the license key that was sent to you on purchase. This enables plugin updates & support.', 'gravityview'), |
|
572 | 572 | 'type' => 'edd_license', |
573 | 573 | 'data-pending-text' => __('Verifying license…', 'gravityview'), |
574 | 574 | 'default_value' => $default_settings['license_key'], |
575 | - 'class' => ( '' == $this->get_app_setting( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key', |
|
575 | + 'class' => ('' == $this->get_app_setting('license_key')) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key', |
|
576 | 576 | ), |
577 | 577 | array( |
578 | 578 | 'name' => 'license_key_response', |
@@ -589,8 +589,8 @@ discard block |
||
589 | 589 | 'type' => 'text', |
590 | 590 | 'validate' => 'email', |
591 | 591 | 'default_value' => $default_settings['support-email'], |
592 | - 'label' => __( 'Support Email', 'gravityview' ), |
|
593 | - 'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ), |
|
592 | + 'label' => __('Support Email', 'gravityview'), |
|
593 | + 'description' => __('In order to provide responses to your support requests, please provide your email address.', 'gravityview'), |
|
594 | 594 | 'class' => 'code regular-text', |
595 | 595 | ), |
596 | 596 | /** |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | array( |
600 | 600 | 'name' => 'support_port', |
601 | 601 | 'type' => 'radio', |
602 | - 'label' => __( 'Show Support Port?', 'gravityview' ), |
|
602 | + 'label' => __('Show Support Port?', 'gravityview'), |
|
603 | 603 | 'default_value' => $default_settings['support_port'], |
604 | 604 | 'horizontal' => 1, |
605 | 605 | 'choices' => array( |
@@ -612,13 +612,13 @@ discard block |
||
612 | 612 | 'value' => '0', |
613 | 613 | ), |
614 | 614 | ), |
615 | - 'tooltip' => '<p><img src="' . esc_url_raw( plugins_url('assets/images/screenshots/beacon.png', GRAVITYVIEW_FILE ) ) . '" alt="' . esc_attr__( 'The Support Port looks like this.', 'gravityview' ) . '" class="alignright" style="max-width:40px; margin:.5em;" />' . esc_html__('The Support Port provides quick access to how-to articles and tutorials. For administrators, it also makes it easy to contact support.', 'gravityview') . '</p>', |
|
616 | - 'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ), |
|
615 | + 'tooltip' => '<p><img src="'.esc_url_raw(plugins_url('assets/images/screenshots/beacon.png', GRAVITYVIEW_FILE)).'" alt="'.esc_attr__('The Support Port looks like this.', 'gravityview').'" class="alignright" style="max-width:40px; margin:.5em;" />'.esc_html__('The Support Port provides quick access to how-to articles and tutorials. For administrators, it also makes it easy to contact support.', 'gravityview').'</p>', |
|
616 | + 'description' => __('Show the Support Port on GravityView pages?', 'gravityview'), |
|
617 | 617 | ), |
618 | 618 | array( |
619 | 619 | 'name' => 'no-conflict-mode', |
620 | 620 | 'type' => 'radio', |
621 | - 'label' => __( 'No-Conflict Mode', 'gravityview' ), |
|
621 | + 'label' => __('No-Conflict Mode', 'gravityview'), |
|
622 | 622 | 'default_value' => $default_settings['no-conflict-mode'], |
623 | 623 | 'horizontal' => 1, |
624 | 624 | 'choices' => array( |
@@ -631,30 +631,30 @@ discard block |
||
631 | 631 | 'value' => '0', |
632 | 632 | ), |
633 | 633 | ), |
634 | - 'description' => __( 'Set this to ON to prevent extraneous scripts and styles from being printed on GravityView admin pages, reducing conflicts with other plugins and themes.', 'gravityview' ) . ' ' . __('If your Edit View tabs are ugly, enable this setting.', 'gravityview'), |
|
634 | + 'description' => __('Set this to ON to prevent extraneous scripts and styles from being printed on GravityView admin pages, reducing conflicts with other plugins and themes.', 'gravityview').' '.__('If your Edit View tabs are ugly, enable this setting.', 'gravityview'), |
|
635 | 635 | ), |
636 | 636 | array( |
637 | 637 | 'name' => 'delete-on-uninstall', |
638 | 638 | 'type' => 'radio', |
639 | - 'label' => __( 'Remove Data on Delete?', 'gravityview' ), |
|
639 | + 'label' => __('Remove Data on Delete?', 'gravityview'), |
|
640 | 640 | 'default_value' => $default_settings['delete-on-uninstall'], |
641 | 641 | 'horizontal' => 1, |
642 | 642 | 'choices' => array( |
643 | 643 | array( |
644 | - 'label' => _x( 'Keep GravityView Data', 'Setting: what to do when uninstalling plugin', 'gravityview' ), |
|
644 | + 'label' => _x('Keep GravityView Data', 'Setting: what to do when uninstalling plugin', 'gravityview'), |
|
645 | 645 | 'value' => '0', |
646 | - 'tooltip' => sprintf( '<h6>%s</h6><p>%s</p>', __( 'Keep GravityView content and settings', 'gravityview' ), __( 'If you delete then re-install the plugin, all GravityView data will be kept. Views, settings, etc. will be untouched.', 'gravityview' ) ), |
|
646 | + 'tooltip' => sprintf('<h6>%s</h6><p>%s</p>', __('Keep GravityView content and settings', 'gravityview'), __('If you delete then re-install the plugin, all GravityView data will be kept. Views, settings, etc. will be untouched.', 'gravityview')), |
|
647 | 647 | ), |
648 | 648 | array( |
649 | - 'label' => _x( 'Permanently Delete', 'Setting: what to do when uninstalling plugin', 'gravityview' ), |
|
649 | + 'label' => _x('Permanently Delete', 'Setting: what to do when uninstalling plugin', 'gravityview'), |
|
650 | 650 | 'value' => 'delete', |
651 | - 'tooltip' => sprintf( '<h6>%s</h6><p><span class="howto">%s</span></p><p>%s</p>', __( 'Delete all GravityView content and settings', 'gravityview' ), __( 'If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview' ), __( 'When GravityView is uninstalled and deleted, delete all Views, GravityView entry approvals, GravityView-generated entry notes (including approval and entry creator changes), and GravityView plugin settings. No Gravity Forms data will be touched.', 'gravityview' ) ), |
|
651 | + 'tooltip' => sprintf('<h6>%s</h6><p><span class="howto">%s</span></p><p>%s</p>', __('Delete all GravityView content and settings', 'gravityview'), __('If you delete then re-install GravityView, it will be like installing GravityView for the first time.', 'gravityview'), __('When GravityView is uninstalled and deleted, delete all Views, GravityView entry approvals, GravityView-generated entry notes (including approval and entry creator changes), and GravityView plugin settings. No Gravity Forms data will be touched.', 'gravityview')), |
|
652 | 652 | ), |
653 | 653 | ), |
654 | - 'description' => sprintf( __( 'Should GravityView content and entry approval status be removed from the site when the GravityView plugin is deleted?', 'gravityview' ), __( 'Permanently Delete', 'gravityview' ) ), |
|
654 | + 'description' => sprintf(__('Should GravityView content and entry approval status be removed from the site when the GravityView plugin is deleted?', 'gravityview'), __('Permanently Delete', 'gravityview')), |
|
655 | 655 | ), |
656 | 656 | |
657 | - ) ); |
|
657 | + )); |
|
658 | 658 | |
659 | 659 | |
660 | 660 | |
@@ -662,21 +662,21 @@ discard block |
||
662 | 662 | * Redux backward compatibility |
663 | 663 | * @since 1.7.4 |
664 | 664 | */ |
665 | - foreach ( $fields as &$field ) { |
|
666 | - $field['name'] = isset( $field['name'] ) ? $field['name'] : rgget('id', $field ); |
|
667 | - $field['label'] = isset( $field['label'] ) ? $field['label'] : rgget('title', $field ); |
|
668 | - $field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : rgget('default', $field ); |
|
669 | - $field['description'] = isset( $field['description'] ) ? $field['description'] : rgget('subtitle', $field ); |
|
670 | - |
|
671 | - if( $disabled_attribute ) { |
|
672 | - $field['disabled'] = $disabled_attribute; |
|
665 | + foreach ($fields as &$field) { |
|
666 | + $field['name'] = isset($field['name']) ? $field['name'] : rgget('id', $field); |
|
667 | + $field['label'] = isset($field['label']) ? $field['label'] : rgget('title', $field); |
|
668 | + $field['default_value'] = isset($field['default_value']) ? $field['default_value'] : rgget('default', $field); |
|
669 | + $field['description'] = isset($field['description']) ? $field['description'] : rgget('subtitle', $field); |
|
670 | + |
|
671 | + if ($disabled_attribute) { |
|
672 | + $field['disabled'] = $disabled_attribute; |
|
673 | 673 | } |
674 | 674 | } |
675 | 675 | |
676 | 676 | |
677 | 677 | $sections = array( |
678 | 678 | array( |
679 | - 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
679 | + 'description' => sprintf('<span class="version-info description">%s</span>', sprintf(__('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version)), |
|
680 | 680 | 'fields' => $fields, |
681 | 681 | ) |
682 | 682 | ); |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | 'type' => 'save', |
688 | 688 | ); |
689 | 689 | |
690 | - if( $disabled_attribute ) { |
|
690 | + if ($disabled_attribute) { |
|
691 | 691 | $button['disabled'] = $disabled_attribute; |
692 | 692 | } |
693 | 693 | |
@@ -703,22 +703,22 @@ discard block |
||
703 | 703 | * </code> |
704 | 704 | * @param array $extension_settings Empty array, ready for extension settings! |
705 | 705 | */ |
706 | - $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() ); |
|
706 | + $extension_sections = apply_filters('gravityview/settings/extension/sections', array()); |
|
707 | 707 | |
708 | 708 | // If there are extensions, add a section for them |
709 | - if ( ! empty( $extension_sections ) ) { |
|
709 | + if (!empty($extension_sections)) { |
|
710 | 710 | |
711 | - if( $disabled_attribute ) { |
|
712 | - foreach ( $extension_sections as &$section ) { |
|
713 | - foreach ( $section['fields'] as &$field ) { |
|
711 | + if ($disabled_attribute) { |
|
712 | + foreach ($extension_sections as &$section) { |
|
713 | + foreach ($section['fields'] as &$field) { |
|
714 | 714 | $field['disabled'] = $disabled_attribute; |
715 | 715 | } |
716 | 716 | } |
717 | 717 | } |
718 | 718 | |
719 | - $k = count( $extension_sections ) - 1 ; |
|
720 | - $extension_sections[ $k ]['fields'][] = $button; |
|
721 | - $sections = array_merge( $sections, $extension_sections ); |
|
719 | + $k = count($extension_sections) - 1; |
|
720 | + $extension_sections[$k]['fields'][] = $button; |
|
721 | + $sections = array_merge($sections, $extension_sections); |
|
722 | 722 | } else { |
723 | 723 | // add the 'update settings' button to the general section |
724 | 724 | $sections[0]['fields'][] = $button; |
@@ -734,8 +734,8 @@ discard block |
||
734 | 734 | * |
735 | 735 | * @return mixed |
736 | 736 | */ |
737 | - static public function getSetting( $key ) { |
|
738 | - return self::get_instance()->get_app_setting( $key ); |
|
737 | + static public function getSetting($key) { |
|
738 | + return self::get_instance()->get_app_setting($key); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | } |
@@ -441,8 +441,9 @@ |
||
441 | 441 | $field['name'] = 'gform-settings-save'; |
442 | 442 | $field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton'; |
443 | 443 | |
444 | - if ( ! rgar( $field, 'value' ) ) |
|
445 | - $field['value'] = __( 'Update Settings', 'gravityview' ); |
|
444 | + if ( ! rgar( $field, 'value' ) ) { |
|
445 | + $field['value'] = __( 'Update Settings', 'gravityview' ); |
|
446 | + } |
|
446 | 447 | |
447 | 448 | $output = $this->settings_submit( $field, false ); |
448 | 449 |
@@ -41,7 +41,6 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @see GVCommon::get_forms() |
43 | 43 | * @access public |
44 | - * @param mixed $form_id |
|
45 | 44 | * @return array (id, title) |
46 | 45 | */ |
47 | 46 | function gravityview_get_forms() { |
@@ -53,7 +52,7 @@ discard block |
||
53 | 52 | * |
54 | 53 | * @see GVCommon::get_form_fields() |
55 | 54 | * @access public |
56 | - * @param string|array $form_id (default: '') or $form object |
|
55 | + * @param string|array $form (default: '') or $form object |
|
57 | 56 | * @return array |
58 | 57 | */ |
59 | 58 | function gravityview_get_form_fields( $form = '', $add_default_properties = false, $include_parent_field = true ) { |
@@ -91,6 +90,7 @@ discard block |
||
91 | 90 | * @param int|array $form_ids The ID of the form or an array IDs of the Forms. Zero for all forms. |
92 | 91 | * @param mixed $passed_criteria (default: null) |
93 | 92 | * @param mixed &$total (default: null) |
93 | + * @param integer $total |
|
94 | 94 | * @return mixed False: Error fetching entries. Array: Multi-dimensional array of Gravity Forms entry arrays |
95 | 95 | */ |
96 | 96 | function gravityview_get_entries( $form_ids = null, $passed_criteria = null, &$total = null ) { |
@@ -103,7 +103,6 @@ discard block |
||
103 | 103 | * Since 1.4, supports custom entry slugs. The way that GravityView fetches an entry based on the custom slug is by searching `gravityview_unique_id` meta. The `$entry_slug` is fetched by getting the current query var set by `is_single_entry()` |
104 | 104 | * |
105 | 105 | * @access public |
106 | - * @param mixed $entry_id |
|
107 | 106 | * @param boolean $force_allow_ids Force the get_entry() method to allow passed entry IDs, even if the `gravityview_custom_entry_slug_allow_id` filter returns false. |
108 | 107 | * @param boolean $check_entry_display Check whether the entry is visible for the current View configuration. Default: true {@since 1.14} |
109 | 108 | * @return array|boolean |
@@ -177,7 +176,7 @@ discard block |
||
177 | 176 | * |
178 | 177 | * @param int $view_id ID of the View you want the form of |
179 | 178 | * |
180 | - * @return int |
|
179 | + * @return string |
|
181 | 180 | */ |
182 | 181 | function gravityview_get_form_id( $view_id ) { |
183 | 182 | return GVCommon::get_meta_form_id( $view_id ); |
@@ -188,7 +187,6 @@ discard block |
||
188 | 187 | * |
189 | 188 | * @see GravityView_Template::template_id |
190 | 189 | * |
191 | - * @param int $view_id The ID of the View to get the layout of |
|
192 | 190 | * |
193 | 191 | * @return string GravityView_Template::template_id value. Empty string if not. |
194 | 192 | */ |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * @param mixed $form_id |
22 | 22 | * @return mixed False: no form ID specified or Gravity Forms isn't active. Array: Form returned from Gravity Forms |
23 | 23 | */ |
24 | -function gravityview_get_form( $form_id ) { |
|
25 | - return GVCommon::get_form( $form_id ); |
|
24 | +function gravityview_get_form($form_id) { |
|
25 | + return GVCommon::get_form($form_id); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * @param int|string $entry_slug Entry slug |
33 | 33 | * @return array Gravity Forms form array |
34 | 34 | */ |
35 | -function gravityview_get_form_from_entry_id( $entry_slug ) { |
|
36 | - return GVCommon::get_form_from_entry_id( $entry_slug ); |
|
35 | +function gravityview_get_form_from_entry_id($entry_slug) { |
|
36 | + return GVCommon::get_form_from_entry_id($entry_slug); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string|array $form_id (default: '') or $form object |
57 | 57 | * @return array |
58 | 58 | */ |
59 | -function gravityview_get_form_fields( $form = '', $add_default_properties = false, $include_parent_field = true ) { |
|
60 | - return GVCommon::get_form_fields( $form, $add_default_properties, $include_parent_field ); |
|
59 | +function gravityview_get_form_fields($form = '', $add_default_properties = false, $include_parent_field = true) { |
|
60 | + return GVCommon::get_form_fields($form, $add_default_properties, $include_parent_field); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @param string $form_id (default: '') |
66 | 66 | * @return array |
67 | 67 | */ |
68 | -function gravityview_get_entry_meta( $form_id, $only_default_column = true ) { |
|
69 | - return GVCommon::get_entry_meta( $form_id, $only_default_column ); |
|
68 | +function gravityview_get_entry_meta($form_id, $only_default_column = true) { |
|
69 | + return GVCommon::get_entry_meta($form_id, $only_default_column); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | * @since 1.1.6 |
78 | 78 | * @return array Array of entry IDs |
79 | 79 | */ |
80 | -function gravityview_get_entry_ids( $form_id, $search_criteria = array() ) { |
|
81 | - return GVCommon::get_entry_ids( $form_id, $search_criteria ); |
|
80 | +function gravityview_get_entry_ids($form_id, $search_criteria = array()) { |
|
81 | + return GVCommon::get_entry_ids($form_id, $search_criteria); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | * @param mixed &$total (default: null) |
94 | 94 | * @return mixed False: Error fetching entries. Array: Multi-dimensional array of Gravity Forms entry arrays |
95 | 95 | */ |
96 | -function gravityview_get_entries( $form_ids = null, $passed_criteria = null, &$total = null ) { |
|
97 | - return GVCommon::get_entries( $form_ids, $passed_criteria, $total ); |
|
96 | +function gravityview_get_entries($form_ids = null, $passed_criteria = null, &$total = null) { |
|
97 | + return GVCommon::get_entries($form_ids, $passed_criteria, $total); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @param boolean $check_entry_display Check whether the entry is visible for the current View configuration. Default: true {@since 1.14} |
109 | 109 | * @return array|boolean |
110 | 110 | */ |
111 | -function gravityview_get_entry( $entry_slug, $force_allow_ids = false, $check_entry_display = true ) { |
|
112 | - return GVCommon::get_entry( $entry_slug, $force_allow_ids, $check_entry_display ); |
|
111 | +function gravityview_get_entry($entry_slug, $force_allow_ids = false, $check_entry_display = true) { |
|
112 | + return GVCommon::get_entry($entry_slug, $force_allow_ids, $check_entry_display); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param mixed $field_id |
121 | 121 | * @return string |
122 | 122 | */ |
123 | -function gravityview_get_field_label( $form, $field_id ) { |
|
124 | - return GVCommon::get_field_label( $form, $field_id ); |
|
123 | +function gravityview_get_field_label($form, $field_id) { |
|
124 | + return GVCommon::get_field_label($form, $field_id); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | * @param string|int $field_id |
138 | 138 | * @return array |
139 | 139 | */ |
140 | -function gravityview_get_field( $form, $field_id ) { |
|
141 | - return GVCommon::get_field( $form, $field_id ); |
|
140 | +function gravityview_get_field($form, $field_id) { |
|
141 | + return GVCommon::get_field($form, $field_id); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | |
@@ -151,16 +151,16 @@ discard block |
||
151 | 151 | * @param WP_Post $post WordPress post object |
152 | 152 | * @return boolean True: yep, GravityView; No: not! |
153 | 153 | */ |
154 | -function has_gravityview_shortcode( $post = NULL ) { |
|
155 | - return GVCommon::has_gravityview_shortcode( $post ); |
|
154 | +function has_gravityview_shortcode($post = NULL) { |
|
155 | + return GVCommon::has_gravityview_shortcode($post); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * Placeholder until the recursive has_shortcode() patch is merged |
160 | 160 | * @see https://core.trac.wordpress.org/ticket/26343#comment:10 |
161 | 161 | */ |
162 | -function gravityview_has_shortcode_r( $content, $tag = 'gravityview' ) { |
|
163 | - return GVCommon::has_shortcode_r( $content, $tag ); |
|
162 | +function gravityview_has_shortcode_r($content, $tag = 'gravityview') { |
|
163 | + return GVCommon::has_shortcode_r($content, $tag); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * @param int $form_id Gravity Forms form ID |
169 | 169 | * @return array Array with view details |
170 | 170 | */ |
171 | -function gravityview_get_connected_views( $form_id ) { |
|
172 | - return GVCommon::get_connected_views( $form_id ); |
|
171 | +function gravityview_get_connected_views($form_id) { |
|
172 | + return GVCommon::get_connected_views($form_id); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return int |
181 | 181 | */ |
182 | -function gravityview_get_form_id( $view_id ) { |
|
183 | - return GVCommon::get_meta_form_id( $view_id ); |
|
182 | +function gravityview_get_form_id($view_id) { |
|
183 | + return GVCommon::get_meta_form_id($view_id); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | * |
193 | 193 | * @return string GravityView_Template::template_id value. Empty string if not. |
194 | 194 | */ |
195 | -function gravityview_get_template_id( $post_id ) { |
|
196 | - return GVCommon::get_meta_template_id( $post_id ); |
|
195 | +function gravityview_get_template_id($post_id) { |
|
196 | + return GVCommon::get_meta_template_id($post_id); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | * @param int $post_id View ID |
204 | 204 | * @return array Associative array of settings with plugin defaults used if not set by the View |
205 | 205 | */ |
206 | -function gravityview_get_template_settings( $post_id ) { |
|
207 | - return GVCommon::get_template_settings( $post_id ); |
|
206 | +function gravityview_get_template_settings($post_id) { |
|
207 | + return GVCommon::get_template_settings($post_id); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | * @param string $key Key for the setting |
217 | 217 | * @return mixed|null Setting value, or NULL if not set. |
218 | 218 | */ |
219 | -function gravityview_get_template_setting( $post_id, $key ) { |
|
220 | - return GVCommon::get_template_setting( $post_id, $key ); |
|
219 | +function gravityview_get_template_setting($post_id, $key) { |
|
220 | + return GVCommon::get_template_setting($post_id, $key); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @filter `gravityview_register_directory_template` Fetch available View templates |
232 | 232 | * @param array $templates Templates to show |
233 | 233 | */ |
234 | - $templates = apply_filters( 'gravityview_register_directory_template', array() ); |
|
234 | + $templates = apply_filters('gravityview_register_directory_template', array()); |
|
235 | 235 | |
236 | 236 | return $templates; |
237 | 237 | } |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @param int $post_id View ID |
267 | 267 | * @return array Multi-array of fields with first level being the field zones. See code comment. |
268 | 268 | */ |
269 | -function gravityview_get_directory_fields( $post_id ) { |
|
270 | - return GVCommon::get_directory_fields( $post_id ); |
|
269 | +function gravityview_get_directory_fields($post_id) { |
|
270 | + return GVCommon::get_directory_fields($post_id); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -278,8 +278,8 @@ discard block |
||
278 | 278 | * @param string $current Field ID of field used to sort |
279 | 279 | * @return string html |
280 | 280 | */ |
281 | -function gravityview_get_sortable_fields( $formid, $current = '' ) { |
|
282 | - return GVCommon::get_sortable_fields( $formid, $current ); |
|
281 | +function gravityview_get_sortable_fields($formid, $current = '') { |
|
282 | + return GVCommon::get_sortable_fields($formid, $current); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | |
@@ -289,8 +289,8 @@ discard block |
||
289 | 289 | * @param mixed $field_id Field ID or Field array |
290 | 290 | * @return string field type |
291 | 291 | */ |
292 | -function gravityview_get_field_type( $form = null , $field_id = '' ) { |
|
293 | - return GVCommon::get_field_type( $form, $field_id ); |
|
292 | +function gravityview_get_field_type($form = null, $field_id = '') { |
|
293 | + return GVCommon::get_field_type($form, $field_id); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | |
@@ -302,15 +302,15 @@ discard block |
||
302 | 302 | * @param array $atts (default: array()) |
303 | 303 | * @return string HTML of the output. Empty string if $view_id is empty. |
304 | 304 | */ |
305 | -function get_gravityview( $view_id = '', $atts = array() ) { |
|
306 | - if( !empty( $view_id ) ) { |
|
305 | +function get_gravityview($view_id = '', $atts = array()) { |
|
306 | + if (!empty($view_id)) { |
|
307 | 307 | $atts['id'] = $view_id; |
308 | - $args = wp_parse_args( $atts, GravityView_View_Data::get_default_args() ); |
|
308 | + $args = wp_parse_args($atts, GravityView_View_Data::get_default_args()); |
|
309 | 309 | $GravityView_frontend = GravityView_frontend::getInstance(); |
310 | - $GravityView_frontend->setGvOutputData( GravityView_View_Data::getInstance( $view_id ) ); |
|
311 | - $GravityView_frontend->set_context_view_id( $view_id ); |
|
310 | + $GravityView_frontend->setGvOutputData(GravityView_View_Data::getInstance($view_id)); |
|
311 | + $GravityView_frontend->set_context_view_id($view_id); |
|
312 | 312 | $GravityView_frontend->set_entry_data(); |
313 | - return $GravityView_frontend->render_view( $args ); |
|
313 | + return $GravityView_frontend->render_view($args); |
|
314 | 314 | } |
315 | 315 | return ''; |
316 | 316 | } |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param array $atts (default: array()) |
324 | 324 | * @return void |
325 | 325 | */ |
326 | -function the_gravityview( $view_id = '', $atts = array() ) { |
|
327 | - echo get_gravityview( $view_id, $atts ); |
|
326 | +function the_gravityview($view_id = '', $atts = array()) { |
|
327 | + echo get_gravityview($view_id, $atts); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | |
@@ -345,17 +345,17 @@ discard block |
||
345 | 345 | * @param array $form Gravity Forms form |
346 | 346 | * @param array $view_fields GravityView fields array |
347 | 347 | */ |
348 | -function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) { |
|
348 | +function gravityview_view_has_single_checkbox_or_radio($form, $view_fields) { |
|
349 | 349 | |
350 | - if( $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) { |
|
350 | + if ($form_fields = GFFormsModel::get_fields_by_type($form, array('checkbox', 'radio'))) { |
|
351 | 351 | |
352 | 352 | /** @var GF_Field_Radio|GF_Field_Checkbox $form_field */ |
353 | - foreach( $form_fields as $form_field ) { |
|
353 | + foreach ($form_fields as $form_field) { |
|
354 | 354 | $field_id = $form_field->id; |
355 | - foreach( $view_fields as $zone ) { |
|
356 | - foreach( $zone as $field ) { |
|
355 | + foreach ($view_fields as $zone) { |
|
356 | + foreach ($zone as $field) { |
|
357 | 357 | // If it's an input, not the parent and the parent ID matches a checkbox or radio |
358 | - if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) { |
|
358 | + if ((strpos($field['id'], '.') > 0) && floor($field['id']) === floor($field_id)) { |
|
359 | 359 | return true; |
360 | 360 | } |
361 | 361 | } |
@@ -170,7 +170,6 @@ |
||
170 | 170 | * |
171 | 171 | * @since 1.5.1 |
172 | 172 | * @param array $visibility_caps Array of capabilities to display in field dropdown. |
173 | - * @param string $field_type Type of field options to render (`field` or `widget`) |
|
174 | 173 | * @param string $template_id Table slug |
175 | 174 | * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
176 | 175 | * @param string $context What context are we in? Example: `single` or `directory` |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | |
229 | 229 | self::getInstance()->set_entry( $entry ); |
230 | 230 | |
231 | - $base = GravityView_API::directory_link( $post_id, true ); |
|
231 | + $base = GravityView_API::directory_link( $post_id, true ); |
|
232 | 232 | |
233 | 233 | if( empty( $base ) ) { |
234 | 234 | do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: '.$post_id ); |
@@ -238,13 +238,13 @@ discard block |
||
238 | 238 | // Use the slug instead of the ID for consistent security |
239 | 239 | $entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry ); |
240 | 240 | |
241 | - $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
|
241 | + $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
|
242 | 242 | |
243 | 243 | $actionurl = add_query_arg( array( |
244 | 244 | 'action' => 'delete', |
245 | 245 | 'entry_id' => $entry_slug, |
246 | 246 | 'gvid' => $view_id, |
247 | - 'view_id' => $view_id, |
|
247 | + 'view_id' => $view_id, |
|
248 | 248 | ), $base ); |
249 | 249 | |
250 | 250 | $url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' ); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @copyright Copyright 2014, Katz Web Services, Inc. |
13 | 13 | */ |
14 | 14 | |
15 | -if ( ! defined( 'WPINC' ) ) { |
|
15 | +if (!defined('WPINC')) { |
|
16 | 16 | die; |
17 | 17 | } |
18 | 18 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | function __construct() { |
32 | 32 | |
33 | - self::$file = plugin_dir_path( __FILE__ ); |
|
33 | + self::$file = plugin_dir_path(__FILE__); |
|
34 | 34 | |
35 | 35 | $this->add_hooks(); |
36 | 36 | } |
@@ -39,22 +39,22 @@ discard block |
||
39 | 39 | * @since 1.9.2 |
40 | 40 | */ |
41 | 41 | private function add_hooks() { |
42 | - add_action( 'wp', array( $this, 'process_delete' ), 10000 ); |
|
42 | + add_action('wp', array($this, 'process_delete'), 10000); |
|
43 | 43 | |
44 | - add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field'), 10, 3 ); |
|
44 | + add_filter('gravityview_entry_default_fields', array($this, 'add_default_field'), 10, 3); |
|
45 | 45 | |
46 | - add_action( 'gravityview_before', array( $this, 'display_message' ) ); |
|
46 | + add_action('gravityview_before', array($this, 'display_message')); |
|
47 | 47 | |
48 | 48 | // For the Delete Entry Link, you don't want visible to all users. |
49 | - add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps'), 10, 5 ); |
|
49 | + add_filter('gravityview_field_visibility_caps', array($this, 'modify_visibility_caps'), 10, 5); |
|
50 | 50 | |
51 | 51 | // Modify the field options based on the name of the field type |
52 | - add_filter( 'gravityview_template_delete_link_options', array( $this, 'delete_link_field_options' ), 10, 5 ); |
|
52 | + add_filter('gravityview_template_delete_link_options', array($this, 'delete_link_field_options'), 10, 5); |
|
53 | 53 | |
54 | 54 | // add template path to check for field |
55 | - add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
55 | + add_filter('gravityview_template_paths', array($this, 'add_template_path')); |
|
56 | 56 | |
57 | - add_action( 'gravityview/edit-entry/publishing-action/after', array( $this, 'add_delete_button'), 10, 3 ); |
|
57 | + add_action('gravityview/edit-entry/publishing-action/after', array($this, 'add_delete_button'), 10, 3); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | static function getInstance() { |
67 | 67 | |
68 | - if( empty( self::$instance ) ) { |
|
68 | + if (empty(self::$instance)) { |
|
69 | 69 | self::$instance = new self; |
70 | 70 | } |
71 | 71 | |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * @since 1.5.1 |
79 | 79 | * @param array $file_paths List of template paths ordered |
80 | 80 | */ |
81 | - function add_template_path( $file_paths ) { |
|
81 | + function add_template_path($file_paths) { |
|
82 | 82 | |
83 | 83 | // Index 100 is the default GravityView template path. |
84 | 84 | // Index 110 is Edit Entry link |
85 | - $file_paths[ 115 ] = self::$file; |
|
85 | + $file_paths[115] = self::$file; |
|
86 | 86 | |
87 | 87 | return $file_paths; |
88 | 88 | } |
@@ -98,17 +98,17 @@ discard block |
||
98 | 98 | * @param [type] $input_type [description] |
99 | 99 | * @return [type] [description] |
100 | 100 | */ |
101 | - function delete_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
101 | + function delete_link_field_options($field_options, $template_id, $field_id, $context, $input_type) { |
|
102 | 102 | |
103 | 103 | // Always a link, never a filter |
104 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
104 | + unset($field_options['show_as_link'], $field_options['search_filter']); |
|
105 | 105 | |
106 | 106 | // Delete Entry link should only appear to visitors capable of editing entries |
107 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
107 | + unset($field_options['only_loggedin'], $field_options['only_loggedin_cap']); |
|
108 | 108 | |
109 | 109 | $add_option['delete_link'] = array( |
110 | 110 | 'type' => 'text', |
111 | - 'label' => __( 'Delete Link Text', 'gravityview' ), |
|
111 | + 'label' => __('Delete Link Text', 'gravityview'), |
|
112 | 112 | 'desc' => NULL, |
113 | 113 | 'value' => __('Delete Entry', 'gravityview'), |
114 | 114 | 'merge_tags' => true, |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | |
117 | 117 | $field_options['allow_edit_cap'] = array( |
118 | 118 | 'type' => 'select', |
119 | - 'label' => __( 'Allow the following users to delete the entry:', 'gravityview' ), |
|
120 | - 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
119 | + 'label' => __('Allow the following users to delete the entry:', 'gravityview'), |
|
120 | + 'choices' => GravityView_Render_Settings::get_cap_choices($template_id, $field_id, $context, $input_type), |
|
121 | 121 | 'tooltip' => 'allow_edit_cap', |
122 | 122 | 'class' => 'widefat', |
123 | 123 | 'value' => 'read', // Default: entry creator |
124 | 124 | ); |
125 | 125 | |
126 | 126 | |
127 | - return array_merge( $add_option, $field_options ); |
|
127 | + return array_merge($add_option, $field_options); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @param string|array $form form_ID or form object |
137 | 137 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
138 | 138 | */ |
139 | - function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
139 | + function add_default_field($entry_default_fields, $form = array(), $zone = '') { |
|
140 | 140 | |
141 | 141 | $entry_default_fields['delete_link'] = array( |
142 | 142 | 'label' => __('Delete Entry', 'gravityview'), |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * @since 1.5.1 |
153 | 153 | * @param array $available_fields |
154 | 154 | */ |
155 | - function add_available_field( $available_fields = array() ) { |
|
155 | + function add_available_field($available_fields = array()) { |
|
156 | 156 | |
157 | 157 | $available_fields['delete_link'] = array( |
158 | - 'label_text' => __( 'Delete Entry', 'gravityview' ), |
|
158 | + 'label_text' => __('Delete Entry', 'gravityview'), |
|
159 | 159 | 'field_id' => 'delete_link', |
160 | 160 | 'label_type' => 'field', |
161 | 161 | 'input_type' => 'delete_link', |
@@ -177,15 +177,15 @@ discard block |
||
177 | 177 | * @param string $input_type (textarea, list, select, etc.) |
178 | 178 | * @return array Array of field options with `label`, `value`, `type`, `default` keys |
179 | 179 | */ |
180 | - public function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
180 | + public function modify_visibility_caps($visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '') { |
|
181 | 181 | |
182 | 182 | $caps = $visibility_caps; |
183 | 183 | |
184 | 184 | // If we're configuring fields in the edit context, we want a limited selection |
185 | - if( $field_id === 'delete_link' ) { |
|
185 | + if ($field_id === 'delete_link') { |
|
186 | 186 | |
187 | 187 | // Remove other built-in caps. |
188 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
188 | + unset($caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts']); |
|
189 | 189 | |
190 | 190 | $caps['read'] = _x('Entry Creator', 'User capability', 'gravityview'); |
191 | 191 | } |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * @since 1.5.1 |
200 | 200 | * @param [type] $entry [description] |
201 | 201 | */ |
202 | - function set_entry( $entry = null ) { |
|
203 | - $this->entry = empty( $entry ) ? GravityView_View::getInstance()->entries[0] : $entry; |
|
202 | + function set_entry($entry = null) { |
|
203 | + $this->entry = empty($entry) ? GravityView_View::getInstance()->entries[0] : $entry; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | * @param int $entry_id Entry ID |
211 | 211 | * @return string Key used to validate request |
212 | 212 | */ |
213 | - public static function get_nonce_key( $entry_id ) { |
|
214 | - return sprintf( 'delete_%s', $entry_id ); |
|
213 | + public static function get_nonce_key($entry_id) { |
|
214 | + return sprintf('delete_%s', $entry_id); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | |
@@ -224,30 +224,30 @@ discard block |
||
224 | 224 | * @param array $entry Gravity Forms entry array |
225 | 225 | * @return string|null If directory link is valid, the URL to process the delete request. Otherwise, `NULL`. |
226 | 226 | */ |
227 | - public static function get_delete_link( $entry, $view_id = 0, $post_id = null ) { |
|
227 | + public static function get_delete_link($entry, $view_id = 0, $post_id = null) { |
|
228 | 228 | |
229 | - self::getInstance()->set_entry( $entry ); |
|
229 | + self::getInstance()->set_entry($entry); |
|
230 | 230 | |
231 | - $base = GravityView_API::directory_link( $post_id, true ); |
|
231 | + $base = GravityView_API::directory_link($post_id, true); |
|
232 | 232 | |
233 | - if( empty( $base ) ) { |
|
234 | - do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: '.$post_id ); |
|
233 | + if (empty($base)) { |
|
234 | + do_action('gravityview_log_error', __METHOD__.' - Post ID does not exist: '.$post_id); |
|
235 | 235 | return NULL; |
236 | 236 | } |
237 | 237 | |
238 | 238 | // Use the slug instead of the ID for consistent security |
239 | - $entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry ); |
|
239 | + $entry_slug = GravityView_API::get_entry_slug($entry['id'], $entry); |
|
240 | 240 | |
241 | - $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
|
241 | + $view_id = empty($view_id) ? gravityview_get_view_id() : $view_id; |
|
242 | 242 | |
243 | - $actionurl = add_query_arg( array( |
|
243 | + $actionurl = add_query_arg(array( |
|
244 | 244 | 'action' => 'delete', |
245 | 245 | 'entry_id' => $entry_slug, |
246 | 246 | 'gvid' => $view_id, |
247 | 247 | 'view_id' => $view_id, |
248 | - ), $base ); |
|
248 | + ), $base); |
|
249 | 249 | |
250 | - $url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' ); |
|
250 | + $url = wp_nonce_url($actionurl, 'delete_'.$entry_slug, 'delete'); |
|
251 | 251 | |
252 | 252 | return $url; |
253 | 253 | } |
@@ -261,10 +261,10 @@ discard block |
||
261 | 261 | * @param array $entry Gravity Forms entry array |
262 | 262 | * @param int $view_id GravityView View ID |
263 | 263 | */ |
264 | - function add_delete_button( $form = array(), $entry = array(), $view_id = NULL ) { |
|
264 | + function add_delete_button($form = array(), $entry = array(), $view_id = NULL) { |
|
265 | 265 | |
266 | 266 | // Only show the link to those who are allowed to see it. |
267 | - if( !self::check_user_cap_delete_entry( $entry ) ) { |
|
267 | + if (!self::check_user_cap_delete_entry($entry)) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | * @filter `gravityview/delete-entry/show-delete-button` Should the Delete button be shown in the Edit Entry screen? |
273 | 273 | * @param boolean $show_entry Default: true |
274 | 274 | */ |
275 | - $show_delete_button = apply_filters( 'gravityview/delete-entry/show-delete-button', true ); |
|
275 | + $show_delete_button = apply_filters('gravityview/delete-entry/show-delete-button', true); |
|
276 | 276 | |
277 | 277 | // If the button is hidden by the filter, don't show. |
278 | - if( !$show_delete_button ) { |
|
278 | + if (!$show_delete_button) { |
|
279 | 279 | return; |
280 | 280 | } |
281 | 281 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | 'onclick' => self::get_confirm_dialog(), |
286 | 286 | ); |
287 | 287 | |
288 | - echo gravityview_get_link( self::get_delete_link( $entry, $view_id ), esc_attr__( 'Delete', 'gravityview' ), $attributes ); |
|
288 | + echo gravityview_get_link(self::get_delete_link($entry, $view_id), esc_attr__('Delete', 'gravityview'), $attributes); |
|
289 | 289 | |
290 | 290 | } |
291 | 291 | |
@@ -305,39 +305,39 @@ discard block |
||
305 | 305 | function process_delete() { |
306 | 306 | |
307 | 307 | // If the form is submitted |
308 | - if( RGForms::get("action") === "delete") { |
|
308 | + if (RGForms::get("action") === "delete") { |
|
309 | 309 | |
310 | - $nonce_key = self::get_nonce_key( $_GET['entry_id'] ); |
|
310 | + $nonce_key = self::get_nonce_key($_GET['entry_id']); |
|
311 | 311 | |
312 | 312 | // Make sure it's a valid request |
313 | - check_admin_referer( $nonce_key, 'delete' ); |
|
313 | + check_admin_referer($nonce_key, 'delete'); |
|
314 | 314 | |
315 | 315 | // Get the entry slug |
316 | - $entry_slug = esc_attr( $_GET['entry_id'] ); |
|
316 | + $entry_slug = esc_attr($_GET['entry_id']); |
|
317 | 317 | |
318 | 318 | // See if there's an entry there |
319 | - $entry = gravityview_get_entry( $entry_slug ); |
|
319 | + $entry = gravityview_get_entry($entry_slug); |
|
320 | 320 | |
321 | - if( $entry ) { |
|
321 | + if ($entry) { |
|
322 | 322 | |
323 | - $has_permission = $this->user_can_delete_entry( $entry ); |
|
323 | + $has_permission = $this->user_can_delete_entry($entry); |
|
324 | 324 | |
325 | - if( is_wp_error( $has_permission ) ) { |
|
325 | + if (is_wp_error($has_permission)) { |
|
326 | 326 | |
327 | 327 | $messages = array( |
328 | - 'message' => urlencode( $has_permission->get_error_message() ), |
|
328 | + 'message' => urlencode($has_permission->get_error_message()), |
|
329 | 329 | 'status' => 'error', |
330 | 330 | ); |
331 | 331 | |
332 | 332 | } else { |
333 | 333 | |
334 | 334 | // Delete the entry |
335 | - $delete_response = $this->delete_or_trash_entry( $entry['id'] ); |
|
335 | + $delete_response = $this->delete_or_trash_entry($entry['id']); |
|
336 | 336 | |
337 | - if( is_wp_error( $delete_response ) ) { |
|
337 | + if (is_wp_error($delete_response)) { |
|
338 | 338 | |
339 | 339 | $messages = array( |
340 | - 'message' => urlencode( $delete_response->get_error_message() ), |
|
340 | + 'message' => urlencode($delete_response->get_error_message()), |
|
341 | 341 | 'status' => 'error', |
342 | 342 | ); |
343 | 343 | |
@@ -353,18 +353,18 @@ discard block |
||
353 | 353 | |
354 | 354 | } else { |
355 | 355 | |
356 | - do_action('gravityview_log_debug', __METHOD__ . ' Delete entry failed: there was no entry with the entry slug '. $entry_slug ); |
|
356 | + do_action('gravityview_log_debug', __METHOD__.' Delete entry failed: there was no entry with the entry slug '.$entry_slug); |
|
357 | 357 | |
358 | 358 | $messages = array( |
359 | - 'message' => urlencode( __('The entry does not exist.', 'gravityview') ), |
|
359 | + 'message' => urlencode(__('The entry does not exist.', 'gravityview')), |
|
360 | 360 | 'status' => 'error', |
361 | 361 | ); |
362 | 362 | } |
363 | 363 | |
364 | - $redirect_to_base = esc_url_raw( remove_query_arg( array( 'action' ) ) ); |
|
365 | - $redirect_to = add_query_arg( $messages, $redirect_to_base ); |
|
364 | + $redirect_to_base = esc_url_raw(remove_query_arg(array('action'))); |
|
365 | + $redirect_to = add_query_arg($messages, $redirect_to_base); |
|
366 | 366 | |
367 | - wp_safe_redirect( $redirect_to ); |
|
367 | + wp_safe_redirect($redirect_to); |
|
368 | 368 | |
369 | 369 | exit(); |
370 | 370 | |
@@ -384,9 +384,9 @@ discard block |
||
384 | 384 | * @since 1.13.1 |
385 | 385 | * @param string $delete_mode Delete mode: `trash` or `delete`. Default: `delete` |
386 | 386 | */ |
387 | - $delete_mode = apply_filters( 'gravityview/delete-entry/mode', 'delete' ); |
|
387 | + $delete_mode = apply_filters('gravityview/delete-entry/mode', 'delete'); |
|
388 | 388 | |
389 | - return ( 'trash' === $delete_mode ) ? 'trash' : 'delete'; |
|
389 | + return ('trash' === $delete_mode) ? 'trash' : 'delete'; |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -394,37 +394,37 @@ discard block |
||
394 | 394 | * @see GFAPI::delete_entry() |
395 | 395 | * @return WP_Error|boolean GFAPI::delete_entry() returns a WP_Error on error |
396 | 396 | */ |
397 | - private function delete_or_trash_entry( $entry_id ) { |
|
397 | + private function delete_or_trash_entry($entry_id) { |
|
398 | 398 | |
399 | 399 | $mode = $this->get_delete_mode(); |
400 | 400 | |
401 | - if( 'delete' === $mode ) { |
|
401 | + if ('delete' === $mode) { |
|
402 | 402 | |
403 | - do_action( 'gravityview_log_debug', __METHOD__ . ' Starting delete entry: ', $entry_id ); |
|
403 | + do_action('gravityview_log_debug', __METHOD__.' Starting delete entry: ', $entry_id); |
|
404 | 404 | |
405 | 405 | // Delete the entry |
406 | - $delete_response = GFAPI::delete_entry( $entry_id ); |
|
406 | + $delete_response = GFAPI::delete_entry($entry_id); |
|
407 | 407 | |
408 | - if( ! is_wp_error( $delete_response ) ) { |
|
408 | + if (!is_wp_error($delete_response)) { |
|
409 | 409 | $delete_response = 'deleted'; |
410 | 410 | } |
411 | 411 | |
412 | - do_action( 'gravityview_log_debug', __METHOD__ . ' Delete response: ', $delete_response ); |
|
412 | + do_action('gravityview_log_debug', __METHOD__.' Delete response: ', $delete_response); |
|
413 | 413 | |
414 | 414 | } else { |
415 | 415 | |
416 | - do_action( 'gravityview_log_debug', __METHOD__ . ' Starting trash entry: ', $entry_id ); |
|
416 | + do_action('gravityview_log_debug', __METHOD__.' Starting trash entry: ', $entry_id); |
|
417 | 417 | |
418 | - $trashed = GFAPI::update_entry_property( $entry_id, 'status', 'trash' ); |
|
418 | + $trashed = GFAPI::update_entry_property($entry_id, 'status', 'trash'); |
|
419 | 419 | new GravityView_Cache; |
420 | 420 | |
421 | - if( ! $trashed ) { |
|
422 | - $delete_response = new WP_Error( 'trash_entry_failed', __('Moving the entry to the trash failed.', 'gravityview' ) ); |
|
421 | + if (!$trashed) { |
|
422 | + $delete_response = new WP_Error('trash_entry_failed', __('Moving the entry to the trash failed.', 'gravityview')); |
|
423 | 423 | } else { |
424 | 424 | $delete_response = 'trashed'; |
425 | 425 | } |
426 | 426 | |
427 | - do_action( 'gravityview_log_debug', __METHOD__ . ' Trashed? ', $delete_response ); |
|
427 | + do_action('gravityview_log_debug', __METHOD__.' Trashed? ', $delete_response); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | return $delete_response; |
@@ -439,13 +439,13 @@ discard block |
||
439 | 439 | public function verify_nonce() { |
440 | 440 | |
441 | 441 | // No delete entry request was made |
442 | - if( empty( $_GET['entry_id'] ) || empty( $_GET['delete'] ) ) { |
|
442 | + if (empty($_GET['entry_id']) || empty($_GET['delete'])) { |
|
443 | 443 | return false; |
444 | 444 | } |
445 | 445 | |
446 | - $nonce_key = self::get_nonce_key( $_GET['entry_id'] ); |
|
446 | + $nonce_key = self::get_nonce_key($_GET['entry_id']); |
|
447 | 447 | |
448 | - $valid = wp_verify_nonce( $_GET['delete'], $nonce_key ); |
|
448 | + $valid = wp_verify_nonce($_GET['delete'], $nonce_key); |
|
449 | 449 | |
450 | 450 | /** |
451 | 451 | * @filter `gravityview/delete-entry/verify_nonce` Override Delete Entry nonce validation. Return true to declare nonce valid. |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
455 | 455 | * @param string $nonce_key Name of nonce action used in wp_verify_nonce. $_GET['delete'] holds the nonce value itself. Default: `delete_{entry_id}` |
456 | 456 | */ |
457 | - $valid = apply_filters( 'gravityview/delete-entry/verify_nonce', $valid, $nonce_key ); |
|
457 | + $valid = apply_filters('gravityview/delete-entry/verify_nonce', $valid, $nonce_key); |
|
458 | 458 | |
459 | 459 | return $valid; |
460 | 460 | } |
@@ -473,9 +473,9 @@ discard block |
||
473 | 473 | * @filter `gravityview/delete-entry/confirm-text` Modify the Delete Entry Javascript confirmation text |
474 | 474 | * @param string $confirm Default: "Are you sure you want to delete this entry? This cannot be undone." |
475 | 475 | */ |
476 | - $confirm = apply_filters( 'gravityview/delete-entry/confirm-text', $confirm ); |
|
476 | + $confirm = apply_filters('gravityview/delete-entry/confirm-text', $confirm); |
|
477 | 477 | |
478 | - return 'return window.confirm(\''. esc_js( $confirm ) .'\');'; |
|
478 | + return 'return window.confirm(\''.esc_js($confirm).'\');'; |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | /** |
@@ -489,34 +489,34 @@ discard block |
||
489 | 489 | * @param array $entry Gravity Forms entry array |
490 | 490 | * @return boolean|WP_Error True: can edit form. WP_Error: nope. |
491 | 491 | */ |
492 | - function user_can_delete_entry( $entry = array() ) { |
|
492 | + function user_can_delete_entry($entry = array()) { |
|
493 | 493 | |
494 | 494 | $error = NULL; |
495 | 495 | |
496 | - if( ! $this->verify_nonce() ) { |
|
497 | - $error = __( 'The link to delete this entry is not valid; it may have expired.', 'gravityview'); |
|
496 | + if (!$this->verify_nonce()) { |
|
497 | + $error = __('The link to delete this entry is not valid; it may have expired.', 'gravityview'); |
|
498 | 498 | } |
499 | 499 | |
500 | - if( ! self::check_user_cap_delete_entry( $entry ) ) { |
|
501 | - $error = __( 'You do not have permission to delete this entry.', 'gravityview'); |
|
500 | + if (!self::check_user_cap_delete_entry($entry)) { |
|
501 | + $error = __('You do not have permission to delete this entry.', 'gravityview'); |
|
502 | 502 | } |
503 | 503 | |
504 | - if( $entry['status'] === 'trash' ) { |
|
505 | - if( 'trash' === $this->get_delete_mode() ) { |
|
506 | - $error = __( 'The entry is already in the trash.', 'gravityview' ); |
|
504 | + if ($entry['status'] === 'trash') { |
|
505 | + if ('trash' === $this->get_delete_mode()) { |
|
506 | + $error = __('The entry is already in the trash.', 'gravityview'); |
|
507 | 507 | } else { |
508 | - $error = __( 'You cannot delete the entry; it is already in the trash.', 'gravityview' ); |
|
508 | + $error = __('You cannot delete the entry; it is already in the trash.', 'gravityview'); |
|
509 | 509 | } |
510 | 510 | } |
511 | 511 | |
512 | 512 | // No errors; everything's fine here! |
513 | - if( empty( $error ) ) { |
|
513 | + if (empty($error)) { |
|
514 | 514 | return true; |
515 | 515 | } |
516 | 516 | |
517 | - do_action('gravityview_log_error', 'GravityView_Delete_Entry[user_can_delete_entry]' . $error ); |
|
517 | + do_action('gravityview_log_error', 'GravityView_Delete_Entry[user_can_delete_entry]'.$error); |
|
518 | 518 | |
519 | - return new WP_Error( 'gravityview-delete-entry-permissions', $error ); |
|
519 | + return new WP_Error('gravityview-delete-entry-permissions', $error); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | |
@@ -531,77 +531,77 @@ discard block |
||
531 | 531 | * @param int $view_id Pass a View ID to check caps against. If not set, check against current View (optional) |
532 | 532 | * @return bool |
533 | 533 | */ |
534 | - public static function check_user_cap_delete_entry( $entry, $field = array(), $view_id = 0 ) { |
|
534 | + public static function check_user_cap_delete_entry($entry, $field = array(), $view_id = 0) { |
|
535 | 535 | $gravityview_view = GravityView_View::getInstance(); |
536 | 536 | |
537 | 537 | $current_user = wp_get_current_user(); |
538 | 538 | |
539 | - $entry_id = isset( $entry['id'] ) ? $entry['id'] : NULL; |
|
539 | + $entry_id = isset($entry['id']) ? $entry['id'] : NULL; |
|
540 | 540 | |
541 | 541 | // Or if they can delete any entries (as defined in Gravity Forms), we're good. |
542 | - if( GVCommon::has_cap( array( 'gravityforms_delete_entries', 'gravityview_delete_others_entries' ), $entry_id ) ) { |
|
542 | + if (GVCommon::has_cap(array('gravityforms_delete_entries', 'gravityview_delete_others_entries'), $entry_id)) { |
|
543 | 543 | |
544 | - do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Current user has `gravityforms_delete_entries` or `gravityview_delete_others_entries` capability.' ); |
|
544 | + do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Current user has `gravityforms_delete_entries` or `gravityview_delete_others_entries` capability.'); |
|
545 | 545 | |
546 | 546 | return true; |
547 | 547 | } |
548 | 548 | |
549 | 549 | |
550 | 550 | // If field options are passed, check if current user can view the link |
551 | - if( !empty( $field ) ) { |
|
551 | + if (!empty($field)) { |
|
552 | 552 | |
553 | 553 | // If capability is not defined, something is not right! |
554 | - if( empty( $field['allow_edit_cap'] ) ) { |
|
554 | + if (empty($field['allow_edit_cap'])) { |
|
555 | 555 | |
556 | - do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Cannot read delete entry field caps', $field ); |
|
556 | + do_action('gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Cannot read delete entry field caps', $field); |
|
557 | 557 | |
558 | 558 | return false; |
559 | 559 | } |
560 | 560 | |
561 | - if( GVCommon::has_cap( $field['allow_edit_cap'] ) ) { |
|
561 | + if (GVCommon::has_cap($field['allow_edit_cap'])) { |
|
562 | 562 | |
563 | 563 | // Do not return true if cap is read, as we need to check if the current user created the entry |
564 | - if( $field['allow_edit_cap'] !== 'read' ) { |
|
564 | + if ($field['allow_edit_cap'] !== 'read') { |
|
565 | 565 | return true; |
566 | 566 | } |
567 | 567 | |
568 | 568 | } else { |
569 | 569 | |
570 | - do_action( 'gravityview_log_debug', sprintf( 'GravityView_Delete_Entry[check_user_cap_delete_entry] User %s is not authorized to view delete entry link ', $current_user->ID ) ); |
|
570 | + do_action('gravityview_log_debug', sprintf('GravityView_Delete_Entry[check_user_cap_delete_entry] User %s is not authorized to view delete entry link ', $current_user->ID)); |
|
571 | 571 | |
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | |
575 | 575 | } |
576 | 576 | |
577 | - if( !isset( $entry['created_by'] ) ) { |
|
577 | + if (!isset($entry['created_by'])) { |
|
578 | 578 | |
579 | 579 | do_action('gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Entry `created_by` doesn\'t exist.'); |
580 | 580 | |
581 | 581 | return false; |
582 | 582 | } |
583 | 583 | |
584 | - $view_id = empty( $view_id ) ? $gravityview_view->getViewId() : $view_id; |
|
584 | + $view_id = empty($view_id) ? $gravityview_view->getViewId() : $view_id; |
|
585 | 585 | |
586 | 586 | // Only checks user_delete view option if view is already set |
587 | - if( $view_id ) { |
|
587 | + if ($view_id) { |
|
588 | 588 | |
589 | - $current_view = gravityview_get_current_view_data( $view_id ); |
|
589 | + $current_view = gravityview_get_current_view_data($view_id); |
|
590 | 590 | |
591 | - $user_delete = isset( $current_view['atts']['user_delete'] ) ? $current_view['atts']['user_delete'] : false; |
|
591 | + $user_delete = isset($current_view['atts']['user_delete']) ? $current_view['atts']['user_delete'] : false; |
|
592 | 592 | |
593 | - if( empty( $user_delete ) ) { |
|
593 | + if (empty($user_delete)) { |
|
594 | 594 | |
595 | - do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] User Delete is disabled. Returning false.' ); |
|
595 | + do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] User Delete is disabled. Returning false.'); |
|
596 | 596 | |
597 | 597 | return false; |
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
601 | 601 | // If the logged-in user is the same as the user who created the entry, we're good. |
602 | - if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
602 | + if (is_user_logged_in() && intval($current_user->ID) === intval($entry['created_by'])) { |
|
603 | 603 | |
604 | - do_action('gravityview_log_debug', sprintf( 'GravityView_Delete_Entry[check_user_cap_delete_entry] User %s created the entry.', $current_user->ID ) ); |
|
604 | + do_action('gravityview_log_debug', sprintf('GravityView_Delete_Entry[check_user_cap_delete_entry] User %s created the entry.', $current_user->ID)); |
|
605 | 605 | |
606 | 606 | return true; |
607 | 607 | } |
@@ -622,27 +622,27 @@ discard block |
||
622 | 622 | * @param int $current_view_id The ID of the View being rendered |
623 | 623 | * @return void |
624 | 624 | */ |
625 | - public function display_message( $current_view_id = 0 ) { |
|
625 | + public function display_message($current_view_id = 0) { |
|
626 | 626 | |
627 | - if( empty( $_GET['status'] ) || ! self::verify_nonce() ) { |
|
627 | + if (empty($_GET['status']) || !self::verify_nonce()) { |
|
628 | 628 | return; |
629 | 629 | } |
630 | 630 | |
631 | 631 | // Entry wasn't deleted from current View |
632 | - if( intval( $_GET['gvid'] ) !== intval( $current_view_id ) ) { |
|
632 | + if (intval($_GET['gvid']) !== intval($current_view_id)) { |
|
633 | 633 | return; |
634 | 634 | } |
635 | 635 | |
636 | - $status = esc_attr( $_GET['status'] ); |
|
636 | + $status = esc_attr($_GET['status']); |
|
637 | 637 | $message_from_url = rgget('message'); |
638 | - $message_from_url = urldecode( stripslashes_deep( $message_from_url ) ); |
|
638 | + $message_from_url = urldecode(stripslashes_deep($message_from_url)); |
|
639 | 639 | $class = ''; |
640 | 640 | |
641 | - switch ( $status ) { |
|
641 | + switch ($status) { |
|
642 | 642 | case 'error': |
643 | 643 | $class = ' gv-error error'; |
644 | 644 | $error_message = __('There was an error deleting the entry: %s', 'gravityview'); |
645 | - $message = sprintf( $error_message, $message_from_url ); |
|
645 | + $message = sprintf($error_message, $message_from_url); |
|
646 | 646 | break; |
647 | 647 | case 'trashed': |
648 | 648 | $message = __('The entry was successfully moved to the trash.', 'gravityview'); |
@@ -659,10 +659,10 @@ discard block |
||
659 | 659 | * @param string $status Message status (`error` or `success`) |
660 | 660 | * @param string $message_from_url The original error message, if any, without the "There was an error deleting the entry:" prefix |
661 | 661 | */ |
662 | - $message = apply_filters( 'gravityview/delete-entry/message', esc_attr( $message ), $status, $message_from_url ); |
|
662 | + $message = apply_filters('gravityview/delete-entry/message', esc_attr($message), $status, $message_from_url); |
|
663 | 663 | |
664 | 664 | // DISPLAY ERROR/SUCCESS MESSAGE |
665 | - echo '<div class="gv-notice' . esc_attr( $class ) .'">'. $message .'</div>'; |
|
665 | + echo '<div class="gv-notice'.esc_attr($class).'">'.$message.'</div>'; |
|
666 | 666 | } |
667 | 667 | |
668 | 668 |
@@ -69,7 +69,6 @@ |
||
69 | 69 | * Change wording for the Edit context to read Entry Creator |
70 | 70 | * |
71 | 71 | * @param array $visibility_caps Array of capabilities to display in field dropdown. |
72 | - * @param string $field_type Type of field options to render (`field` or `widget`) |
|
73 | 72 | * @param string $template_id Table slug |
74 | 73 | * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
75 | 74 | * @param string $context What context are we in? Example: `single` or `directory` |
@@ -10,175 +10,175 @@ |
||
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_Admin { |
18 | 18 | |
19 | - protected $loader; |
|
19 | + protected $loader; |
|
20 | 20 | |
21 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
22 | - $this->loader = $loader; |
|
23 | - } |
|
21 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
22 | + $this->loader = $loader; |
|
23 | + } |
|
24 | 24 | |
25 | - function load() { |
|
26 | - |
|
27 | - if( !is_admin() ) { |
|
28 | - return; |
|
29 | - } |
|
30 | - |
|
31 | - // Add Edit Link as a default field, outside those set in the Gravity Form form |
|
32 | - add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
33 | - |
|
34 | - // For the Edit Entry Link, you don't want visible to all users. |
|
35 | - add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
25 | + function load() { |
|
26 | + |
|
27 | + if( !is_admin() ) { |
|
28 | + return; |
|
29 | + } |
|
30 | + |
|
31 | + // Add Edit Link as a default field, outside those set in the Gravity Form form |
|
32 | + add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
33 | + |
|
34 | + // For the Edit Entry Link, you don't want visible to all users. |
|
35 | + add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
36 | 36 | |
37 | - // Modify the field options based on the name of the field type |
|
38 | - add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 ); |
|
37 | + // Modify the field options based on the name of the field type |
|
38 | + add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 ); |
|
39 | 39 | |
40 | - // add tooltips |
|
41 | - add_filter( 'gravityview_tooltips', array( $this, 'tooltips') ); |
|
42 | - |
|
43 | - // custom fields' options for zone EDIT |
|
44 | - add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 ); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
49 | - * @param array $entry_default_fields Existing fields |
|
50 | - * @param string|array $form form_ID or form object |
|
51 | - * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
52 | - */ |
|
53 | - function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
54 | - |
|
55 | - if( $zone !== 'edit' ) { |
|
56 | - |
|
57 | - $entry_default_fields['edit_link'] = array( |
|
58 | - 'label' => __('Edit Entry', 'gravityview'), |
|
59 | - 'type' => 'edit_link', |
|
60 | - 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
61 | - ); |
|
62 | - |
|
63 | - } |
|
64 | - |
|
65 | - return $entry_default_fields; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Change wording for the Edit context to read Entry Creator |
|
70 | - * |
|
71 | - * @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
72 | - * @param string $field_type Type of field options to render (`field` or `widget`) |
|
73 | - * @param string $template_id Table slug |
|
74 | - * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
75 | - * @param string $context What context are we in? Example: `single` or `directory` |
|
76 | - * @param string $input_type (textarea, list, select, etc.) |
|
77 | - * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
78 | - */ |
|
79 | - function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
80 | - |
|
81 | - $caps = $visibility_caps; |
|
82 | - |
|
83 | - // If we're configuring fields in the edit context, we want a limited selection |
|
84 | - if( $context === 'edit' ) { |
|
85 | - |
|
86 | - // Remove other built-in caps. |
|
87 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
88 | - |
|
89 | - $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
90 | - } |
|
91 | - |
|
92 | - return $caps; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Add "Edit Link Text" setting to the edit_link field settings |
|
97 | - * @param [type] $field_options [description] |
|
98 | - * @param [type] $template_id [description] |
|
99 | - * @param [type] $field_id [description] |
|
100 | - * @param [type] $context [description] |
|
101 | - * @param [type] $input_type [description] |
|
102 | - * @return [type] [description] |
|
103 | - */ |
|
104 | - function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
105 | - |
|
106 | - // Always a link, never a filter |
|
107 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
108 | - |
|
109 | - // Edit Entry link should only appear to visitors capable of editing entries |
|
110 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
111 | - |
|
112 | - $add_option['edit_link'] = array( |
|
113 | - 'type' => 'text', |
|
114 | - 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
115 | - 'desc' => NULL, |
|
116 | - 'value' => __('Edit Entry', 'gravityview'), |
|
117 | - 'merge_tags' => true, |
|
118 | - ); |
|
119 | - |
|
120 | - return array_merge( $add_option, $field_options ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Add tooltips |
|
125 | - * @param array $tooltips Existing tooltips |
|
126 | - * @return array Modified tooltips |
|
127 | - */ |
|
128 | - function tooltips( $tooltips ) { |
|
129 | - |
|
130 | - $return = $tooltips; |
|
131 | - |
|
132 | - $return['allow_edit_cap'] = array( |
|
133 | - 'title' => __('Limiting Edit Access', 'gravityview'), |
|
134 | - 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
135 | - ); |
|
136 | - |
|
137 | - return $return; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Manipulate the fields' options for the EDIT ENTRY screen |
|
142 | - * @param [type] $field_options [description] |
|
143 | - * @param [type] $template_id [description] |
|
144 | - * @param [type] $field_id [description] |
|
145 | - * @param [type] $context [description] |
|
146 | - * @param [type] $input_type [description] |
|
147 | - * @return [type] [description] |
|
148 | - */ |
|
149 | - function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
150 | - |
|
151 | - // We only want to modify the settings for the edit context |
|
152 | - if( 'edit' !== $context ) { |
|
153 | - |
|
154 | - /** |
|
155 | - * @since 1.8.4 |
|
156 | - */ |
|
157 | - $field_options['new_window'] = array( |
|
158 | - 'type' => 'checkbox', |
|
159 | - 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
160 | - 'value' => false, |
|
161 | - ); |
|
162 | - |
|
163 | - return $field_options; |
|
164 | - } |
|
165 | - |
|
166 | - // Entry field is only for logged in users |
|
167 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
168 | - |
|
169 | - $add_options = array( |
|
170 | - 'allow_edit_cap' => array( |
|
171 | - 'type' => 'select', |
|
172 | - 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
173 | - 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
174 | - 'tooltip' => 'allow_edit_cap', |
|
175 | - 'class' => 'widefat', |
|
176 | - 'value' => 'read', // Default: entry creator |
|
177 | - ), |
|
178 | - ); |
|
179 | - |
|
180 | - return array_merge( $field_options, $add_options ); |
|
181 | - } |
|
40 | + // add tooltips |
|
41 | + add_filter( 'gravityview_tooltips', array( $this, 'tooltips') ); |
|
42 | + |
|
43 | + // custom fields' options for zone EDIT |
|
44 | + add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 ); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
49 | + * @param array $entry_default_fields Existing fields |
|
50 | + * @param string|array $form form_ID or form object |
|
51 | + * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
52 | + */ |
|
53 | + function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
54 | + |
|
55 | + if( $zone !== 'edit' ) { |
|
56 | + |
|
57 | + $entry_default_fields['edit_link'] = array( |
|
58 | + 'label' => __('Edit Entry', 'gravityview'), |
|
59 | + 'type' => 'edit_link', |
|
60 | + 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
61 | + ); |
|
62 | + |
|
63 | + } |
|
64 | + |
|
65 | + return $entry_default_fields; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Change wording for the Edit context to read Entry Creator |
|
70 | + * |
|
71 | + * @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
72 | + * @param string $field_type Type of field options to render (`field` or `widget`) |
|
73 | + * @param string $template_id Table slug |
|
74 | + * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
75 | + * @param string $context What context are we in? Example: `single` or `directory` |
|
76 | + * @param string $input_type (textarea, list, select, etc.) |
|
77 | + * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
78 | + */ |
|
79 | + function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
80 | + |
|
81 | + $caps = $visibility_caps; |
|
82 | + |
|
83 | + // If we're configuring fields in the edit context, we want a limited selection |
|
84 | + if( $context === 'edit' ) { |
|
85 | + |
|
86 | + // Remove other built-in caps. |
|
87 | + unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
88 | + |
|
89 | + $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
90 | + } |
|
91 | + |
|
92 | + return $caps; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Add "Edit Link Text" setting to the edit_link field settings |
|
97 | + * @param [type] $field_options [description] |
|
98 | + * @param [type] $template_id [description] |
|
99 | + * @param [type] $field_id [description] |
|
100 | + * @param [type] $context [description] |
|
101 | + * @param [type] $input_type [description] |
|
102 | + * @return [type] [description] |
|
103 | + */ |
|
104 | + function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
105 | + |
|
106 | + // Always a link, never a filter |
|
107 | + unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
108 | + |
|
109 | + // Edit Entry link should only appear to visitors capable of editing entries |
|
110 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
111 | + |
|
112 | + $add_option['edit_link'] = array( |
|
113 | + 'type' => 'text', |
|
114 | + 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
115 | + 'desc' => NULL, |
|
116 | + 'value' => __('Edit Entry', 'gravityview'), |
|
117 | + 'merge_tags' => true, |
|
118 | + ); |
|
119 | + |
|
120 | + return array_merge( $add_option, $field_options ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Add tooltips |
|
125 | + * @param array $tooltips Existing tooltips |
|
126 | + * @return array Modified tooltips |
|
127 | + */ |
|
128 | + function tooltips( $tooltips ) { |
|
129 | + |
|
130 | + $return = $tooltips; |
|
131 | + |
|
132 | + $return['allow_edit_cap'] = array( |
|
133 | + 'title' => __('Limiting Edit Access', 'gravityview'), |
|
134 | + 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
135 | + ); |
|
136 | + |
|
137 | + return $return; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Manipulate the fields' options for the EDIT ENTRY screen |
|
142 | + * @param [type] $field_options [description] |
|
143 | + * @param [type] $template_id [description] |
|
144 | + * @param [type] $field_id [description] |
|
145 | + * @param [type] $context [description] |
|
146 | + * @param [type] $input_type [description] |
|
147 | + * @return [type] [description] |
|
148 | + */ |
|
149 | + function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
150 | + |
|
151 | + // We only want to modify the settings for the edit context |
|
152 | + if( 'edit' !== $context ) { |
|
153 | + |
|
154 | + /** |
|
155 | + * @since 1.8.4 |
|
156 | + */ |
|
157 | + $field_options['new_window'] = array( |
|
158 | + 'type' => 'checkbox', |
|
159 | + 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
160 | + 'value' => false, |
|
161 | + ); |
|
162 | + |
|
163 | + return $field_options; |
|
164 | + } |
|
165 | + |
|
166 | + // Entry field is only for logged in users |
|
167 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
168 | + |
|
169 | + $add_options = array( |
|
170 | + 'allow_edit_cap' => array( |
|
171 | + 'type' => 'select', |
|
172 | + 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
173 | + 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
174 | + 'tooltip' => 'allow_edit_cap', |
|
175 | + 'class' => 'widefat', |
|
176 | + 'value' => 'read', // Default: entry creator |
|
177 | + ), |
|
178 | + ); |
|
179 | + |
|
180 | + return array_merge( $field_options, $add_options ); |
|
181 | + } |
|
182 | 182 | |
183 | 183 | |
184 | 184 | } // end class |
185 | 185 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @copyright Copyright 2014, Katz Web Services, Inc. |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'WPINC' ) ) { |
|
12 | +if (!defined('WPINC')) { |
|
13 | 13 | die; |
14 | 14 | } |
15 | 15 | |
@@ -18,30 +18,30 @@ discard block |
||
18 | 18 | |
19 | 19 | protected $loader; |
20 | 20 | |
21 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
21 | + function __construct(GravityView_Edit_Entry $loader) { |
|
22 | 22 | $this->loader = $loader; |
23 | 23 | } |
24 | 24 | |
25 | 25 | function load() { |
26 | 26 | |
27 | - if( !is_admin() ) { |
|
27 | + if (!is_admin()) { |
|
28 | 28 | return; |
29 | 29 | } |
30 | 30 | |
31 | 31 | // Add Edit Link as a default field, outside those set in the Gravity Form form |
32 | - add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
32 | + add_filter('gravityview_entry_default_fields', array($this, 'add_default_field'), 10, 3); |
|
33 | 33 | |
34 | 34 | // For the Edit Entry Link, you don't want visible to all users. |
35 | - add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
35 | + add_filter('gravityview_field_visibility_caps', array($this, 'modify_visibility_caps'), 10, 5); |
|
36 | 36 | |
37 | 37 | // Modify the field options based on the name of the field type |
38 | - add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 ); |
|
38 | + add_filter('gravityview_template_edit_link_options', array($this, 'edit_link_field_options'), 10, 5); |
|
39 | 39 | |
40 | 40 | // add tooltips |
41 | - add_filter( 'gravityview_tooltips', array( $this, 'tooltips') ); |
|
41 | + add_filter('gravityview_tooltips', array($this, 'tooltips')); |
|
42 | 42 | |
43 | 43 | // custom fields' options for zone EDIT |
44 | - add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 ); |
|
44 | + add_filter('gravityview_template_field_options', array($this, 'field_options'), 10, 5); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * @param string|array $form form_ID or form object |
51 | 51 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
52 | 52 | */ |
53 | - function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
53 | + function add_default_field($entry_default_fields, $form = array(), $zone = '') { |
|
54 | 54 | |
55 | - if( $zone !== 'edit' ) { |
|
55 | + if ($zone !== 'edit') { |
|
56 | 56 | |
57 | 57 | $entry_default_fields['edit_link'] = array( |
58 | 58 | 'label' => __('Edit Entry', 'gravityview'), |
@@ -76,17 +76,17 @@ discard block |
||
76 | 76 | * @param string $input_type (textarea, list, select, etc.) |
77 | 77 | * @return array Array of field options with `label`, `value`, `type`, `default` keys |
78 | 78 | */ |
79 | - function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
79 | + function modify_visibility_caps($visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '') { |
|
80 | 80 | |
81 | 81 | $caps = $visibility_caps; |
82 | 82 | |
83 | 83 | // If we're configuring fields in the edit context, we want a limited selection |
84 | - if( $context === 'edit' ) { |
|
84 | + if ($context === 'edit') { |
|
85 | 85 | |
86 | 86 | // Remove other built-in caps. |
87 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
87 | + unset($caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts']); |
|
88 | 88 | |
89 | - $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
89 | + $caps['read'] = _x('Entry Creator', 'User capability', 'gravityview'); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | return $caps; |
@@ -101,23 +101,23 @@ discard block |
||
101 | 101 | * @param [type] $input_type [description] |
102 | 102 | * @return [type] [description] |
103 | 103 | */ |
104 | - function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
104 | + function edit_link_field_options($field_options, $template_id, $field_id, $context, $input_type) { |
|
105 | 105 | |
106 | 106 | // Always a link, never a filter |
107 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
107 | + unset($field_options['show_as_link'], $field_options['search_filter']); |
|
108 | 108 | |
109 | 109 | // Edit Entry link should only appear to visitors capable of editing entries |
110 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
110 | + unset($field_options['only_loggedin'], $field_options['only_loggedin_cap']); |
|
111 | 111 | |
112 | 112 | $add_option['edit_link'] = array( |
113 | 113 | 'type' => 'text', |
114 | - 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
114 | + 'label' => __('Edit Link Text', 'gravityview'), |
|
115 | 115 | 'desc' => NULL, |
116 | 116 | 'value' => __('Edit Entry', 'gravityview'), |
117 | 117 | 'merge_tags' => true, |
118 | 118 | ); |
119 | 119 | |
120 | - return array_merge( $add_option, $field_options ); |
|
120 | + return array_merge($add_option, $field_options); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param array $tooltips Existing tooltips |
126 | 126 | * @return array Modified tooltips |
127 | 127 | */ |
128 | - function tooltips( $tooltips ) { |
|
128 | + function tooltips($tooltips) { |
|
129 | 129 | |
130 | 130 | $return = $tooltips; |
131 | 131 | |
@@ -146,17 +146,17 @@ discard block |
||
146 | 146 | * @param [type] $input_type [description] |
147 | 147 | * @return [type] [description] |
148 | 148 | */ |
149 | - function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
149 | + function field_options($field_options, $template_id, $field_id, $context, $input_type) { |
|
150 | 150 | |
151 | 151 | // We only want to modify the settings for the edit context |
152 | - if( 'edit' !== $context ) { |
|
152 | + if ('edit' !== $context) { |
|
153 | 153 | |
154 | 154 | /** |
155 | 155 | * @since 1.8.4 |
156 | 156 | */ |
157 | 157 | $field_options['new_window'] = array( |
158 | 158 | 'type' => 'checkbox', |
159 | - 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
159 | + 'label' => __('Open link in a new tab or window?', 'gravityview'), |
|
160 | 160 | 'value' => false, |
161 | 161 | ); |
162 | 162 | |
@@ -164,20 +164,20 @@ discard block |
||
164 | 164 | } |
165 | 165 | |
166 | 166 | // Entry field is only for logged in users |
167 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
167 | + unset($field_options['only_loggedin'], $field_options['only_loggedin_cap']); |
|
168 | 168 | |
169 | 169 | $add_options = array( |
170 | 170 | 'allow_edit_cap' => array( |
171 | 171 | 'type' => 'select', |
172 | - 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
173 | - 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
172 | + 'label' => __('Make field editable to:', 'gravityview'), |
|
173 | + 'choices' => GravityView_Render_Settings::get_cap_choices($template_id, $field_id, $context, $input_type), |
|
174 | 174 | 'tooltip' => 'allow_edit_cap', |
175 | 175 | 'class' => 'widefat', |
176 | 176 | 'value' => 'read', // Default: entry creator |
177 | 177 | ), |
178 | 178 | ); |
179 | 179 | |
180 | - return array_merge( $field_options, $add_options ); |
|
180 | + return array_merge($field_options, $add_options); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 |
@@ -1249,7 +1249,7 @@ |
||
1249 | 1249 | /** |
1250 | 1250 | * Override GF Form field properties with the ones defined on the View |
1251 | 1251 | * @param GF_Field $field GF Form field object |
1252 | - * @param array $setting GV field options |
|
1252 | + * @param array $field_setting GV field options |
|
1253 | 1253 | * @since 1.5 |
1254 | 1254 | * @return array |
1255 | 1255 | */ |
@@ -10,18 +10,18 @@ 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 | - protected $loader; |
|
19 | + protected $loader; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var string String used to generate unique nonce for the entry/form/view combination. Allows access to edit page. |
23 | 23 | */ |
24 | - static $nonce_key; |
|
24 | + static $nonce_key; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @since 1.9 |
@@ -41,102 +41,102 @@ discard block |
||
41 | 41 | */ |
42 | 42 | private static $supports_product_fields = false; |
43 | 43 | |
44 | - /** |
|
45 | - * Gravity Forms entry array |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - var $entry; |
|
44 | + /** |
|
45 | + * Gravity Forms entry array |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + var $entry; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Gravity Forms form array |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - var $form; |
|
51 | + /** |
|
52 | + * Gravity Forms form array |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + var $form; |
|
57 | 57 | |
58 | - /** |
|
59 | - * Gravity Forms form array after the form validation process |
|
60 | - * @since 1.13 |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - var $form_after_validation = null; |
|
58 | + /** |
|
59 | + * Gravity Forms form array after the form validation process |
|
60 | + * @since 1.13 |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + var $form_after_validation = null; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Gravity Forms form id |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - var $form_id; |
|
65 | + /** |
|
66 | + * Gravity Forms form id |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + var $form_id; |
|
71 | 71 | |
72 | - /** |
|
73 | - * ID of the current view |
|
74 | - * |
|
75 | - * @var int |
|
76 | - */ |
|
77 | - var $view_id; |
|
72 | + /** |
|
73 | + * ID of the current view |
|
74 | + * |
|
75 | + * @var int |
|
76 | + */ |
|
77 | + var $view_id; |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * Updated entry is valid (GF Validation object) |
|
82 | - * |
|
83 | - * @var array |
|
84 | - */ |
|
85 | - var $is_valid = NULL; |
|
80 | + /** |
|
81 | + * Updated entry is valid (GF Validation object) |
|
82 | + * |
|
83 | + * @var array |
|
84 | + */ |
|
85 | + var $is_valid = NULL; |
|
86 | 86 | |
87 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
88 | - $this->loader = $loader; |
|
89 | - } |
|
87 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
88 | + $this->loader = $loader; |
|
89 | + } |
|
90 | 90 | |
91 | - function load() { |
|
91 | + function load() { |
|
92 | 92 | |
93 | - /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
94 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
93 | + /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
94 | + include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
95 | 95 | |
96 | - // Stop Gravity Forms processing what is ours! |
|
97 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
96 | + // Stop Gravity Forms processing what is ours! |
|
97 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
98 | 98 | |
99 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
99 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
100 | 100 | |
101 | - add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
101 | + add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
102 | 102 | |
103 | - // Disable conditional logic if needed (since 1.9) |
|
104 | - add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
103 | + // Disable conditional logic if needed (since 1.9) |
|
104 | + add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
105 | 105 | |
106 | - // Make sure GF doesn't validate max files (since 1.9) |
|
107 | - add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
106 | + // Make sure GF doesn't validate max files (since 1.9) |
|
107 | + add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
108 | 108 | |
109 | - // Add fields expected by GFFormDisplay::validate() |
|
110 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
109 | + // Add fields expected by GFFormDisplay::validate() |
|
110 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
111 | 111 | |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
118 | - * backend form, we need to prevent them from saving twice. |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - function prevent_maybe_process_form() { |
|
116 | + /** |
|
117 | + * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
118 | + * backend form, we need to prevent them from saving twice. |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + function prevent_maybe_process_form() { |
|
122 | 122 | |
123 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
123 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
124 | 124 | |
125 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
126 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
127 | - } |
|
128 | - } |
|
125 | + if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
126 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Is the current page an Edit Entry page? |
|
132 | - * @return boolean |
|
133 | - */ |
|
134 | - public function is_edit_entry() { |
|
130 | + /** |
|
131 | + * Is the current page an Edit Entry page? |
|
132 | + * @return boolean |
|
133 | + */ |
|
134 | + public function is_edit_entry() { |
|
135 | 135 | |
136 | - $gf_page = ( 'entry' === RGForms::get( 'view' ) ); |
|
136 | + $gf_page = ( 'entry' === RGForms::get( 'view' ) ); |
|
137 | 137 | |
138 | - return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); |
|
139 | - } |
|
138 | + return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); |
|
139 | + } |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * Is the current page an Edit Entry page? |
@@ -147,422 +147,422 @@ discard block |
||
147 | 147 | return !empty( $_POST[ self::$nonce_field ] ); |
148 | 148 | } |
149 | 149 | |
150 | - /** |
|
151 | - * When Edit entry view is requested setup the vars |
|
152 | - */ |
|
153 | - function setup_vars() { |
|
154 | - $gravityview_view = GravityView_View::getInstance(); |
|
150 | + /** |
|
151 | + * When Edit entry view is requested setup the vars |
|
152 | + */ |
|
153 | + function setup_vars() { |
|
154 | + $gravityview_view = GravityView_View::getInstance(); |
|
155 | 155 | |
156 | 156 | |
157 | - $entries = $gravityview_view->getEntries(); |
|
158 | - $this->entry = $entries[0]; |
|
157 | + $entries = $gravityview_view->getEntries(); |
|
158 | + $this->entry = $entries[0]; |
|
159 | 159 | |
160 | 160 | |
161 | - $this->form = $gravityview_view->getForm(); |
|
162 | - $this->form_id = $gravityview_view->getFormId(); |
|
163 | - $this->view_id = $gravityview_view->getViewId(); |
|
161 | + $this->form = $gravityview_view->getForm(); |
|
162 | + $this->form_id = $gravityview_view->getFormId(); |
|
163 | + $this->view_id = $gravityview_view->getViewId(); |
|
164 | 164 | |
165 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
166 | - } |
|
165 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
166 | + } |
|
167 | 167 | |
168 | 168 | |
169 | - /** |
|
170 | - * Load required files and trigger edit flow |
|
171 | - * |
|
172 | - * Run when the is_edit_entry returns true. |
|
173 | - * |
|
174 | - * @param GravityView_View_Data $gv_data GravityView Data object |
|
175 | - * @return void |
|
176 | - */ |
|
177 | - function init( $gv_data ) { |
|
169 | + /** |
|
170 | + * Load required files and trigger edit flow |
|
171 | + * |
|
172 | + * Run when the is_edit_entry returns true. |
|
173 | + * |
|
174 | + * @param GravityView_View_Data $gv_data GravityView Data object |
|
175 | + * @return void |
|
176 | + */ |
|
177 | + function init( $gv_data ) { |
|
178 | 178 | |
179 | - require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
180 | - require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
179 | + require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
180 | + require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
181 | 181 | |
182 | - $this->setup_vars(); |
|
182 | + $this->setup_vars(); |
|
183 | 183 | |
184 | - // Multiple Views embedded, don't proceed if nonce fails |
|
185 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
186 | - return; |
|
187 | - } |
|
184 | + // Multiple Views embedded, don't proceed if nonce fails |
|
185 | + if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
186 | + return; |
|
187 | + } |
|
188 | 188 | |
189 | - // Sorry, you're not allowed here. |
|
190 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
191 | - return; |
|
192 | - } |
|
189 | + // Sorry, you're not allowed here. |
|
190 | + if( false === $this->user_can_edit_entry( true ) ) { |
|
191 | + return; |
|
192 | + } |
|
193 | 193 | |
194 | - $this->print_scripts(); |
|
194 | + $this->print_scripts(); |
|
195 | 195 | |
196 | - $this->process_save(); |
|
196 | + $this->process_save(); |
|
197 | 197 | |
198 | - $this->edit_entry_form(); |
|
198 | + $this->edit_entry_form(); |
|
199 | 199 | |
200 | - } |
|
200 | + } |
|
201 | 201 | |
202 | 202 | |
203 | - /** |
|
204 | - * Force Gravity Forms to output scripts as if it were in the admin |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - function print_scripts() { |
|
208 | - $gravityview_view = GravityView_View::getInstance(); |
|
203 | + /** |
|
204 | + * Force Gravity Forms to output scripts as if it were in the admin |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + function print_scripts() { |
|
208 | + $gravityview_view = GravityView_View::getInstance(); |
|
209 | 209 | |
210 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
210 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
211 | 211 | |
212 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
212 | + GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
213 | 213 | |
214 | - // Sack is required for images |
|
215 | - wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
216 | - } |
|
214 | + // Sack is required for images |
|
215 | + wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * Process edit entry form save |
|
221 | - */ |
|
222 | - function process_save() { |
|
219 | + /** |
|
220 | + * Process edit entry form save |
|
221 | + */ |
|
222 | + function process_save() { |
|
223 | 223 | |
224 | - if( empty( $_POST ) ) { |
|
225 | - return; |
|
226 | - } |
|
224 | + if( empty( $_POST ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | 227 | |
228 | - // Make sure the entry, view, and form IDs are all correct |
|
229 | - $valid = $this->verify_nonce(); |
|
228 | + // Make sure the entry, view, and form IDs are all correct |
|
229 | + $valid = $this->verify_nonce(); |
|
230 | 230 | |
231 | - if( !$valid ) { |
|
232 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
233 | - return; |
|
234 | - } |
|
231 | + if( !$valid ) { |
|
232 | + do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
233 | + return; |
|
234 | + } |
|
235 | 235 | |
236 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
237 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
238 | - return; |
|
239 | - } |
|
236 | + if( $this->entry['id'] !== $_POST['lid'] ) { |
|
237 | + do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
238 | + return; |
|
239 | + } |
|
240 | 240 | |
241 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
241 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
242 | 242 | |
243 | - $this->process_save_process_files( $this->form_id ); |
|
243 | + $this->process_save_process_files( $this->form_id ); |
|
244 | 244 | |
245 | - $this->validate(); |
|
245 | + $this->validate(); |
|
246 | 246 | |
247 | - if( $this->is_valid ) { |
|
247 | + if( $this->is_valid ) { |
|
248 | 248 | |
249 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
249 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
250 | 250 | |
251 | - /** |
|
252 | - * @hack This step is needed to unset the adminOnly from form fields |
|
253 | - */ |
|
254 | - $form = $this->form_prepare_for_save(); |
|
251 | + /** |
|
252 | + * @hack This step is needed to unset the adminOnly from form fields |
|
253 | + */ |
|
254 | + $form = $this->form_prepare_for_save(); |
|
255 | 255 | |
256 | - /** |
|
257 | - * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
258 | - */ |
|
259 | - unset( $_GET['page'] ); |
|
256 | + /** |
|
257 | + * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
258 | + */ |
|
259 | + unset( $_GET['page'] ); |
|
260 | 260 | |
261 | - GFFormsModel::save_lead( $form, $this->entry ); |
|
261 | + GFFormsModel::save_lead( $form, $this->entry ); |
|
262 | 262 | |
263 | - // If there's a post associated with the entry, process post fields |
|
264 | - if( !empty( $this->entry['post_id'] ) ) { |
|
265 | - $this->maybe_update_post_fields( $form ); |
|
266 | - } |
|
263 | + // If there's a post associated with the entry, process post fields |
|
264 | + if( !empty( $this->entry['post_id'] ) ) { |
|
265 | + $this->maybe_update_post_fields( $form ); |
|
266 | + } |
|
267 | 267 | |
268 | - // Perform actions normally performed after updating a lead |
|
269 | - $this->after_update(); |
|
268 | + // Perform actions normally performed after updating a lead |
|
269 | + $this->after_update(); |
|
270 | 270 | |
271 | - /** |
|
272 | - * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
273 | - * @param array $form Gravity Forms form array |
|
274 | - * @param string $entry_id Numeric ID of the entry that was updated |
|
275 | - */ |
|
276 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
277 | - } |
|
271 | + /** |
|
272 | + * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
273 | + * @param array $form Gravity Forms form array |
|
274 | + * @param string $entry_id Numeric ID of the entry that was updated |
|
275 | + */ |
|
276 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
277 | + } |
|
278 | 278 | |
279 | - } // process_save |
|
279 | + } // process_save |
|
280 | 280 | |
281 | 281 | |
282 | - /** |
|
283 | - * Have GF handle file uploads |
|
284 | - * |
|
285 | - * Copy of code from GFFormDisplay::process_form() |
|
286 | - * |
|
287 | - * @param int $form_id |
|
288 | - */ |
|
289 | - function process_save_process_files( $form_id ) { |
|
282 | + /** |
|
283 | + * Have GF handle file uploads |
|
284 | + * |
|
285 | + * Copy of code from GFFormDisplay::process_form() |
|
286 | + * |
|
287 | + * @param int $form_id |
|
288 | + */ |
|
289 | + function process_save_process_files( $form_id ) { |
|
290 | 290 | |
291 | - //Loading files that have been uploaded to temp folder |
|
292 | - $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
293 | - if ( ! is_array( $files ) ) { |
|
294 | - $files = array(); |
|
295 | - } |
|
291 | + //Loading files that have been uploaded to temp folder |
|
292 | + $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
293 | + if ( ! is_array( $files ) ) { |
|
294 | + $files = array(); |
|
295 | + } |
|
296 | 296 | |
297 | - RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
298 | - } |
|
297 | + RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
302 | - * Late validation done on self::custom_validation |
|
303 | - * |
|
304 | - * @param $plupload_init array Plupload settings |
|
305 | - * @param $form_id |
|
306 | - * @param $instance |
|
307 | - * @return mixed |
|
308 | - */ |
|
309 | - public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
310 | - if( ! $this->is_edit_entry() ) { |
|
311 | - return $plupload_init; |
|
312 | - } |
|
300 | + /** |
|
301 | + * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
302 | + * Late validation done on self::custom_validation |
|
303 | + * |
|
304 | + * @param $plupload_init array Plupload settings |
|
305 | + * @param $form_id |
|
306 | + * @param $instance |
|
307 | + * @return mixed |
|
308 | + */ |
|
309 | + public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
310 | + if( ! $this->is_edit_entry() ) { |
|
311 | + return $plupload_init; |
|
312 | + } |
|
313 | 313 | |
314 | - $plupload_init['gf_vars']['max_files'] = 0; |
|
314 | + $plupload_init['gf_vars']['max_files'] = 0; |
|
315 | 315 | |
316 | - return $plupload_init; |
|
317 | - } |
|
316 | + return $plupload_init; |
|
317 | + } |
|
318 | 318 | |
319 | 319 | |
320 | - /** |
|
321 | - * Unset adminOnly and convert field input key to string |
|
322 | - * @return array $form |
|
323 | - */ |
|
324 | - private function form_prepare_for_save() { |
|
325 | - $form = $this->form; |
|
320 | + /** |
|
321 | + * Unset adminOnly and convert field input key to string |
|
322 | + * @return array $form |
|
323 | + */ |
|
324 | + private function form_prepare_for_save() { |
|
325 | + $form = $this->form; |
|
326 | 326 | |
327 | - foreach( $form['fields'] as &$field ) { |
|
327 | + foreach( $form['fields'] as &$field ) { |
|
328 | 328 | |
329 | - $field->adminOnly = false; |
|
329 | + $field->adminOnly = false; |
|
330 | 330 | |
331 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
332 | - foreach( $field->inputs as $key => $input ) { |
|
333 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
331 | + if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
332 | + foreach( $field->inputs as $key => $input ) { |
|
333 | + $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | 337 | |
338 | - return $form; |
|
339 | - } |
|
338 | + return $form; |
|
339 | + } |
|
340 | 340 | |
341 | 341 | |
342 | - /** |
|
343 | - * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
344 | - * |
|
345 | - * @param array $form Gravity Forms form |
|
346 | - * |
|
347 | - * @return void |
|
348 | - */ |
|
349 | - function maybe_update_post_fields( $form ) { |
|
342 | + /** |
|
343 | + * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
344 | + * |
|
345 | + * @param array $form Gravity Forms form |
|
346 | + * |
|
347 | + * @return void |
|
348 | + */ |
|
349 | + function maybe_update_post_fields( $form ) { |
|
350 | 350 | |
351 | - $post_id = $this->entry['post_id']; |
|
351 | + $post_id = $this->entry['post_id']; |
|
352 | 352 | |
353 | - // Security check |
|
354 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
355 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
356 | - return; |
|
357 | - } |
|
353 | + // Security check |
|
354 | + if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
355 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
356 | + return; |
|
357 | + } |
|
358 | 358 | |
359 | - $update_entry = false; |
|
359 | + $update_entry = false; |
|
360 | 360 | |
361 | - $updated_post = $original_post = get_post( $post_id ); |
|
361 | + $updated_post = $original_post = get_post( $post_id ); |
|
362 | 362 | |
363 | - foreach ( $this->entry as $field_id => $value ) { |
|
363 | + foreach ( $this->entry as $field_id => $value ) { |
|
364 | 364 | |
365 | - //todo: only run through the edit entry configured fields |
|
365 | + //todo: only run through the edit entry configured fields |
|
366 | 366 | |
367 | - $field = RGFormsModel::get_field( $form, $field_id ); |
|
367 | + $field = RGFormsModel::get_field( $form, $field_id ); |
|
368 | 368 | |
369 | - if( class_exists('GF_Fields') ) { |
|
370 | - $field = GF_Fields::create( $field ); |
|
371 | - } |
|
369 | + if( class_exists('GF_Fields') ) { |
|
370 | + $field = GF_Fields::create( $field ); |
|
371 | + } |
|
372 | 372 | |
373 | - if( GFCommon::is_post_field( $field ) ) { |
|
373 | + if( GFCommon::is_post_field( $field ) ) { |
|
374 | 374 | |
375 | - // Get the value of the field, including $_POSTed value |
|
376 | - $value = RGFormsModel::get_field_value( $field ); |
|
375 | + // Get the value of the field, including $_POSTed value |
|
376 | + $value = RGFormsModel::get_field_value( $field ); |
|
377 | 377 | |
378 | - // Convert the field object in 1.9 to an array for backward compatibility |
|
379 | - $field_array = GVCommon::get_field_array( $field ); |
|
378 | + // Convert the field object in 1.9 to an array for backward compatibility |
|
379 | + $field_array = GVCommon::get_field_array( $field ); |
|
380 | 380 | |
381 | - switch( $field_array['type'] ) { |
|
381 | + switch( $field_array['type'] ) { |
|
382 | 382 | |
383 | - case 'post_title': |
|
384 | - case 'post_content': |
|
385 | - case 'post_excerpt': |
|
386 | - $updated_post->{$field_array['type']} = $value; |
|
387 | - break; |
|
388 | - case 'post_tags': |
|
389 | - wp_set_post_tags( $post_id, $value, false ); |
|
390 | - break; |
|
391 | - case 'post_category': |
|
383 | + case 'post_title': |
|
384 | + case 'post_content': |
|
385 | + case 'post_excerpt': |
|
386 | + $updated_post->{$field_array['type']} = $value; |
|
387 | + break; |
|
388 | + case 'post_tags': |
|
389 | + wp_set_post_tags( $post_id, $value, false ); |
|
390 | + break; |
|
391 | + case 'post_category': |
|
392 | 392 | |
393 | - $categories = is_array( $value ) ? array_values( $value ) : (array)$value; |
|
394 | - $categories = array_filter( $categories ); |
|
393 | + $categories = is_array( $value ) ? array_values( $value ) : (array)$value; |
|
394 | + $categories = array_filter( $categories ); |
|
395 | 395 | |
396 | - wp_set_post_categories( $post_id, $categories, false ); |
|
396 | + wp_set_post_categories( $post_id, $categories, false ); |
|
397 | 397 | |
398 | - // prepare value to be saved in the entry |
|
399 | - $field = GFCommon::add_categories_as_choices( $field, '' ); |
|
398 | + // prepare value to be saved in the entry |
|
399 | + $field = GFCommon::add_categories_as_choices( $field, '' ); |
|
400 | 400 | |
401 | - // if post_category is type checkbox, then value is an array of inputs |
|
402 | - if( isset( $value[ strval( $field_id ) ] ) ) { |
|
403 | - foreach( $value as $input_id => $val ) { |
|
404 | - $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
|
405 | - $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); |
|
406 | - } |
|
407 | - } else { |
|
408 | - $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
|
409 | - $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); |
|
410 | - } |
|
401 | + // if post_category is type checkbox, then value is an array of inputs |
|
402 | + if( isset( $value[ strval( $field_id ) ] ) ) { |
|
403 | + foreach( $value as $input_id => $val ) { |
|
404 | + $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
|
405 | + $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); |
|
406 | + } |
|
407 | + } else { |
|
408 | + $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
|
409 | + $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); |
|
410 | + } |
|
411 | 411 | |
412 | - break; |
|
413 | - case 'post_custom_field': |
|
412 | + break; |
|
413 | + case 'post_custom_field': |
|
414 | 414 | |
415 | - $input_type = RGFormsModel::get_input_type( $field ); |
|
416 | - $custom_field_name = $field_array['postCustomFieldName']; |
|
415 | + $input_type = RGFormsModel::get_input_type( $field ); |
|
416 | + $custom_field_name = $field_array['postCustomFieldName']; |
|
417 | 417 | |
418 | - // Only certain custom field types are supported |
|
419 | - if( !in_array( $input_type, array( 'list', 'fileupload' ) ) ) { |
|
420 | - update_post_meta( $post_id, $custom_field_name, $value ); |
|
421 | - } |
|
418 | + // Only certain custom field types are supported |
|
419 | + if( !in_array( $input_type, array( 'list', 'fileupload' ) ) ) { |
|
420 | + update_post_meta( $post_id, $custom_field_name, $value ); |
|
421 | + } |
|
422 | 422 | |
423 | - break; |
|
423 | + break; |
|
424 | 424 | |
425 | - case 'post_image': |
|
425 | + case 'post_image': |
|
426 | 426 | |
427 | - $value = ''; |
|
428 | - break; |
|
427 | + $value = ''; |
|
428 | + break; |
|
429 | 429 | |
430 | - } |
|
430 | + } |
|
431 | 431 | |
432 | - //ignore fields that have not changed |
|
433 | - if ( $value === rgget( (string) $field_id, $this->entry ) ) { |
|
434 | - continue; |
|
435 | - } |
|
432 | + //ignore fields that have not changed |
|
433 | + if ( $value === rgget( (string) $field_id, $this->entry ) ) { |
|
434 | + continue; |
|
435 | + } |
|
436 | 436 | |
437 | - // update entry |
|
438 | - if( 'post_category' !== $field->type ) { |
|
439 | - $this->entry[ strval( $field_id ) ] = $value; |
|
440 | - } |
|
437 | + // update entry |
|
438 | + if( 'post_category' !== $field->type ) { |
|
439 | + $this->entry[ strval( $field_id ) ] = $value; |
|
440 | + } |
|
441 | 441 | |
442 | - $update_entry = true; |
|
442 | + $update_entry = true; |
|
443 | 443 | |
444 | - } |
|
444 | + } |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - if( $update_entry ) { |
|
448 | + if( $update_entry ) { |
|
449 | 449 | |
450 | - $return_entry = GFAPI::update_entry( $this->entry ); |
|
450 | + $return_entry = GFAPI::update_entry( $this->entry ); |
|
451 | 451 | |
452 | - if( is_wp_error( $return_entry ) ) { |
|
453 | - do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
|
454 | - } else { |
|
455 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
456 | - } |
|
452 | + if( is_wp_error( $return_entry ) ) { |
|
453 | + do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
|
454 | + } else { |
|
455 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
456 | + } |
|
457 | 457 | |
458 | - } |
|
458 | + } |
|
459 | 459 | |
460 | - $return_post = wp_update_post( $updated_post, true ); |
|
460 | + $return_post = wp_update_post( $updated_post, true ); |
|
461 | 461 | |
462 | - if( is_wp_error( $return_post ) ) { |
|
463 | - do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
|
464 | - } else { |
|
465 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded' ); |
|
466 | - } |
|
462 | + if( is_wp_error( $return_post ) ) { |
|
463 | + do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
|
464 | + } else { |
|
465 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded' ); |
|
466 | + } |
|
467 | 467 | |
468 | - } |
|
468 | + } |
|
469 | 469 | |
470 | - /** |
|
471 | - * Perform actions normally performed after updating a lead |
|
472 | - * |
|
473 | - * @since 1.8 |
|
474 | - * |
|
475 | - * @see GFEntryDetail::lead_detail_page() |
|
476 | - * |
|
477 | - * @return void |
|
478 | - */ |
|
479 | - function after_update() { |
|
470 | + /** |
|
471 | + * Perform actions normally performed after updating a lead |
|
472 | + * |
|
473 | + * @since 1.8 |
|
474 | + * |
|
475 | + * @see GFEntryDetail::lead_detail_page() |
|
476 | + * |
|
477 | + * @return void |
|
478 | + */ |
|
479 | + function after_update() { |
|
480 | 480 | |
481 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
482 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
481 | + do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
482 | + do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
483 | 483 | |
484 | - // Re-define the entry now that we've updated it. |
|
485 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
484 | + // Re-define the entry now that we've updated it. |
|
485 | + $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
486 | 486 | |
487 | - $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
487 | + $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
488 | 488 | |
489 | - // We need to clear the cache because Gravity Forms caches the field values, which |
|
490 | - // we have just updated. |
|
491 | - foreach ($this->form['fields'] as $key => $field) { |
|
492 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
493 | - } |
|
489 | + // We need to clear the cache because Gravity Forms caches the field values, which |
|
490 | + // we have just updated. |
|
491 | + foreach ($this->form['fields'] as $key => $field) { |
|
492 | + GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
493 | + } |
|
494 | 494 | |
495 | - $this->entry = $entry; |
|
496 | - } |
|
495 | + $this->entry = $entry; |
|
496 | + } |
|
497 | 497 | |
498 | 498 | |
499 | - /** |
|
500 | - * Display the Edit Entry form |
|
501 | - * |
|
502 | - * @return [type] [description] |
|
503 | - */ |
|
504 | - public function edit_entry_form() { |
|
499 | + /** |
|
500 | + * Display the Edit Entry form |
|
501 | + * |
|
502 | + * @return [type] [description] |
|
503 | + */ |
|
504 | + public function edit_entry_form() { |
|
505 | 505 | |
506 | - $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
506 | + $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
507 | 507 | |
508 | - ?> |
|
508 | + ?> |
|
509 | 509 | |
510 | 510 | <div class="gv-edit-entry-wrapper"><?php |
511 | 511 | |
512 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
512 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
513 | 513 | |
514 | - /** |
|
515 | - * Fixes weird wpautop() issue |
|
516 | - * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
517 | - */ |
|
518 | - echo gravityview_strip_whitespace( $javascript ); |
|
514 | + /** |
|
515 | + * Fixes weird wpautop() issue |
|
516 | + * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
517 | + */ |
|
518 | + echo gravityview_strip_whitespace( $javascript ); |
|
519 | 519 | |
520 | - ?><h2 class="gv-edit-entry-title"> |
|
520 | + ?><h2 class="gv-edit-entry-title"> |
|
521 | 521 | <span><?php |
522 | 522 | |
523 | - /** |
|
524 | - * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
525 | - * @param string $edit_entry_title Modify the "Edit Entry" title |
|
526 | - * @param GravityView_Edit_Entry_Render $this This object |
|
527 | - */ |
|
528 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
523 | + /** |
|
524 | + * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
525 | + * @param string $edit_entry_title Modify the "Edit Entry" title |
|
526 | + * @param GravityView_Edit_Entry_Render $this This object |
|
527 | + */ |
|
528 | + $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
529 | 529 | |
530 | - echo esc_attr( $edit_entry_title ); |
|
531 | - ?></span> |
|
530 | + echo esc_attr( $edit_entry_title ); |
|
531 | + ?></span> |
|
532 | 532 | </h2> |
533 | 533 | |
534 | 534 | <?php |
535 | 535 | |
536 | - // Display the success message |
|
537 | - if( rgpost('action') === 'update' ) { |
|
536 | + // Display the success message |
|
537 | + if( rgpost('action') === 'update' ) { |
|
538 | 538 | |
539 | - if( ! $this->is_valid ){ |
|
539 | + if( ! $this->is_valid ){ |
|
540 | 540 | |
541 | - // Keeping this compatible with Gravity Forms. |
|
542 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
543 | - $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
541 | + // Keeping this compatible with Gravity Forms. |
|
542 | + $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
543 | + $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
544 | 544 | |
545 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
545 | + echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
546 | 546 | |
547 | - } else { |
|
548 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
547 | + } else { |
|
548 | + $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
549 | 549 | |
550 | - /** |
|
551 | - * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
552 | - * @since 1.5.4 |
|
553 | - * @param string $entry_updated_message Existing message |
|
554 | - * @param int $view_id View ID |
|
555 | - * @param array $entry Gravity Forms entry array |
|
556 | - * @param string $back_link URL to return to the original entry. @since 1.6 |
|
557 | - */ |
|
558 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
550 | + /** |
|
551 | + * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
552 | + * @since 1.5.4 |
|
553 | + * @param string $entry_updated_message Existing message |
|
554 | + * @param int $view_id View ID |
|
555 | + * @param array $entry Gravity Forms entry array |
|
556 | + * @param string $back_link URL to return to the original entry. @since 1.6 |
|
557 | + */ |
|
558 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
559 | 559 | |
560 | - echo GVCommon::generate_notice( $message ); |
|
561 | - } |
|
560 | + echo GVCommon::generate_notice( $message ); |
|
561 | + } |
|
562 | 562 | |
563 | - } |
|
563 | + } |
|
564 | 564 | |
565 | - ?> |
|
565 | + ?> |
|
566 | 566 | |
567 | 567 | <?php // The ID of the form needs to be `gform_{form_id}` for the pluploader ?> |
568 | 568 | |
@@ -570,590 +570,590 @@ discard block |
||
570 | 570 | |
571 | 571 | <?php |
572 | 572 | |
573 | - wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
573 | + wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
574 | 574 | |
575 | - wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
575 | + wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
576 | 576 | |
577 | - // Most of this is needed for GFFormDisplay::validate(), but `gform_unique_id` is needed for file cleanup. |
|
577 | + // Most of this is needed for GFFormDisplay::validate(), but `gform_unique_id` is needed for file cleanup. |
|
578 | 578 | |
579 | - ?> |
|
579 | + ?> |
|
580 | 580 | |
581 | 581 | |
582 | 582 | <?php |
583 | 583 | |
584 | - /** |
|
585 | - * By default, the lead_detail_edit method uses the `RGFormsModel::get_lead_field_value()` method, which doesn't fill in $_POST values when there is a validation error, because it was designed to work in the admin. We want to use the `RGFormsModel::get_field_value()` If the form has been submitted, use the values for the fields. |
|
586 | - */ |
|
587 | - //add_filter( 'gform_get_field_value', array( $this, 'get_field_value' ), 10, 3 ); |
|
584 | + /** |
|
585 | + * By default, the lead_detail_edit method uses the `RGFormsModel::get_lead_field_value()` method, which doesn't fill in $_POST values when there is a validation error, because it was designed to work in the admin. We want to use the `RGFormsModel::get_field_value()` If the form has been submitted, use the values for the fields. |
|
586 | + */ |
|
587 | + //add_filter( 'gform_get_field_value', array( $this, 'get_field_value' ), 10, 3 ); |
|
588 | 588 | |
589 | - // Print the actual form HTML |
|
590 | - $this->render_edit_form(); |
|
589 | + // Print the actual form HTML |
|
590 | + $this->render_edit_form(); |
|
591 | 591 | |
592 | - //echo $this->render_form_buttons(); |
|
592 | + //echo $this->render_form_buttons(); |
|
593 | 593 | |
594 | - ?> |
|
594 | + ?> |
|
595 | 595 | </form> |
596 | 596 | |
597 | 597 | </div> |
598 | 598 | |
599 | 599 | <?php |
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * Display the Edit Entry form in the original Gravity Forms format |
|
604 | - * |
|
605 | - * @since 1.9 |
|
606 | - * |
|
607 | - * @param $form |
|
608 | - * @param $lead |
|
609 | - * @param $view_id |
|
610 | - * |
|
611 | - * @return void |
|
612 | - */ |
|
613 | - private function render_edit_form() { |
|
614 | - |
|
615 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
616 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
617 | - add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
618 | - add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
619 | - |
|
620 | - // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
621 | - unset( $_GET['page'] ); |
|
622 | - |
|
623 | - // TODO: Make sure validation isn't handled by GF |
|
624 | - // TODO: Include CSS for file upload fields |
|
625 | - // TODO: Verify multiple-page forms |
|
626 | - // TODO: Product fields are not editable |
|
627 | - // TODO: Check Updated and Error messages |
|
628 | - |
|
629 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
630 | - |
|
631 | - remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
632 | - remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
633 | - remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
634 | - remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
635 | - |
|
636 | - echo $html; |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
641 | - * @since 1.8 |
|
642 | - * @return string |
|
643 | - */ |
|
644 | - public function render_form_buttons() { |
|
645 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
651 | - * |
|
652 | - * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
653 | - * |
|
654 | - * @param array $form |
|
655 | - * @param boolean $ajax Whether in AJAX mode |
|
656 | - * @param array|string $field_values Passed parameters to the form |
|
657 | - * |
|
658 | - * @since 1.9 |
|
659 | - * |
|
660 | - * @return array Modified form array |
|
661 | - */ |
|
662 | - public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
663 | - |
|
664 | - // In case we have validated the form, use it to inject the validation results into the form render |
|
665 | - if( isset( $this->form_after_validation ) ) { |
|
666 | - $form = $this->form_after_validation; |
|
667 | - } else { |
|
668 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
669 | - } |
|
670 | - |
|
671 | - $form = $this->filter_conditional_logic( $form ); |
|
672 | - |
|
673 | - // for now we don't support Save and Continue feature. |
|
674 | - if( ! self::$supports_save_and_continue ) { |
|
675 | - unset( $form['save'] ); |
|
676 | - } |
|
677 | - |
|
678 | - return $form; |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * |
|
684 | - * Fill-in the saved values into the form inputs |
|
685 | - * |
|
686 | - * @param string $field_content Always empty. |
|
687 | - * @param GF_Field $field |
|
688 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
689 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
690 | - * @param int $form_id Form ID |
|
691 | - * |
|
692 | - * @return mixed |
|
693 | - */ |
|
694 | - function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
695 | - |
|
696 | - // If the form has been submitted, then we don't need to pre-fill the values, |
|
697 | - // Except for fileupload type - run always!! |
|
698 | - if( |
|
699 | - $this->is_edit_entry_submission() && 'fileupload' !== $field->type |
|
700 | - || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
701 | - ) { |
|
702 | - return $field_content; |
|
703 | - } |
|
704 | - |
|
705 | - // Turn on Admin-style display for file upload fields only |
|
706 | - if( 'fileupload' === $field->type ) { |
|
707 | - $_GET['page'] = 'gf_entries'; |
|
708 | - } |
|
709 | - |
|
710 | - // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
711 | - $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
712 | - |
|
713 | - // add categories as choices for Post Category field |
|
714 | - if ( 'post_category' === $field->type ) { |
|
715 | - $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * @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. |
|
720 | - * @param boolean True: override saved values; False: don't override (default) |
|
721 | - * @param $field GF_Field object Gravity Forms field object |
|
722 | - * @since 1.13 |
|
723 | - */ |
|
724 | - $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
725 | - |
|
726 | - // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
727 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
728 | - |
|
729 | - $field_value = array(); |
|
730 | - |
|
731 | - // only accept pre-populated values if the field doesn't have any choice selected. |
|
732 | - $allow_pre_populated = $field->allowsPrepopulate; |
|
733 | - |
|
734 | - foreach ( (array)$field->inputs as $input ) { |
|
735 | - |
|
736 | - $input_id = strval( $input['id'] ); |
|
737 | - |
|
738 | - if ( ! empty( $this->entry[ $input_id ] ) ) { |
|
739 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
740 | - $allow_pre_populated = false; |
|
741 | - } |
|
742 | - |
|
743 | - } |
|
744 | - |
|
745 | - $pre_value = $field->get_value_submission( array(), false ); |
|
746 | - |
|
747 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !empty( $pre_value ) ) ? $field_value : $pre_value; |
|
748 | - |
|
749 | - } else { |
|
750 | - |
|
751 | - $id = intval( $field->id ); |
|
752 | - |
|
753 | - // get pre-populated value if exists |
|
754 | - $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
755 | - |
|
756 | - // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
757 | - // or pre-populated value if not empty and set to override saved value |
|
758 | - $field_value = !empty( $this->entry[ $id ] ) && ! ( $override_saved_value && !empty( $pre_value ) ) ? $this->entry[ $id ] : $pre_value; |
|
759 | - |
|
760 | - // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
761 | - if ( 'post_category' === $field->type && !empty( $field_value ) ) { |
|
762 | - $categories = array(); |
|
763 | - foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
764 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
765 | - } |
|
766 | - $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
767 | - } |
|
600 | + } |
|
768 | 601 | |
769 | - } |
|
602 | + /** |
|
603 | + * Display the Edit Entry form in the original Gravity Forms format |
|
604 | + * |
|
605 | + * @since 1.9 |
|
606 | + * |
|
607 | + * @param $form |
|
608 | + * @param $lead |
|
609 | + * @param $view_id |
|
610 | + * |
|
611 | + * @return void |
|
612 | + */ |
|
613 | + private function render_edit_form() { |
|
770 | 614 | |
771 | - // if value is empty get the default value if defined |
|
772 | - $field_value = $field->get_value_default_if_empty( $field_value ); |
|
773 | - |
|
774 | - /** |
|
775 | - * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
776 | - * @since 1.11 |
|
777 | - * @param mixed $field_value field value used to populate the input |
|
778 | - * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
779 | - */ |
|
780 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
781 | - |
|
782 | - // Prevent any PHP warnings, like undefined index |
|
783 | - ob_start(); |
|
784 | - |
|
785 | - $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
786 | - |
|
787 | - // If there was output, it's an error |
|
788 | - $warnings = ob_get_clean(); |
|
615 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
616 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
617 | + add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
618 | + add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
789 | 619 | |
790 | - if( !empty( $warnings ) ) { |
|
791 | - do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
792 | - } |
|
620 | + // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
621 | + unset( $_GET['page'] ); |
|
793 | 622 | |
794 | - /** |
|
795 | - * Unset hack $_GET['page'] = 'gf_entries' |
|
796 | - * We need the fileupload html field to render with the proper id |
|
797 | - * ( <li id="field_80_16" ... > ) |
|
798 | - */ |
|
799 | - unset( $_GET['page'] ); |
|
623 | + // TODO: Make sure validation isn't handled by GF |
|
624 | + // TODO: Include CSS for file upload fields |
|
625 | + // TODO: Verify multiple-page forms |
|
626 | + // TODO: Product fields are not editable |
|
627 | + // TODO: Check Updated and Error messages |
|
800 | 628 | |
801 | - return $return; |
|
802 | - } |
|
629 | + $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
803 | 630 | |
631 | + remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
632 | + remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
633 | + remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
634 | + remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
804 | 635 | |
805 | - /** |
|
806 | - * Get the posted values from the edit form submission |
|
807 | - * |
|
808 | - * @hack |
|
809 | - * @uses GFFormsModel::get_field_value() |
|
810 | - * @param mixed $value Existing field value, before edit |
|
811 | - * @param array $lead Gravity Forms entry array |
|
812 | - * @param array $field Gravity Forms field array |
|
813 | - * @return string [description] |
|
814 | - */ |
|
815 | - public function get_field_value( $value, $lead, $field ) { |
|
636 | + echo $html; |
|
637 | + } |
|
816 | 638 | |
817 | - // The form's not being edited; use the original value |
|
818 | - if( ! $this->is_edit_entry_submission() ) { |
|
819 | - return $value; |
|
820 | - } |
|
639 | + /** |
|
640 | + * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
641 | + * @since 1.8 |
|
642 | + * @return string |
|
643 | + */ |
|
644 | + public function render_form_buttons() { |
|
645 | + return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
646 | + } |
|
821 | 647 | |
822 | - return GFFormsModel::get_field_value( $field, $lead, true ); |
|
823 | - } |
|
824 | 648 | |
649 | + /** |
|
650 | + * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
651 | + * |
|
652 | + * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
653 | + * |
|
654 | + * @param array $form |
|
655 | + * @param boolean $ajax Whether in AJAX mode |
|
656 | + * @param array|string $field_values Passed parameters to the form |
|
657 | + * |
|
658 | + * @since 1.9 |
|
659 | + * |
|
660 | + * @return array Modified form array |
|
661 | + */ |
|
662 | + public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
825 | 663 | |
664 | + // In case we have validated the form, use it to inject the validation results into the form render |
|
665 | + if( isset( $this->form_after_validation ) ) { |
|
666 | + $form = $this->form_after_validation; |
|
667 | + } else { |
|
668 | + $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
669 | + } |
|
826 | 670 | |
671 | + $form = $this->filter_conditional_logic( $form ); |
|
827 | 672 | |
828 | - // ---- Entry validation |
|
673 | + // for now we don't support Save and Continue feature. |
|
674 | + if( ! self::$supports_save_and_continue ) { |
|
675 | + unset( $form['save'] ); |
|
676 | + } |
|
829 | 677 | |
830 | - /** |
|
831 | - * Add field keys that Gravity Forms expects. |
|
832 | - * |
|
833 | - * @see GFFormDisplay::validate() |
|
834 | - * @param array $form GF Form |
|
835 | - * @return array Modified GF Form |
|
836 | - */ |
|
837 | - function gform_pre_validation( $form ) { |
|
678 | + return $form; |
|
679 | + } |
|
838 | 680 | |
839 | - if( ! $this->verify_nonce() ) { |
|
840 | - return $form; |
|
841 | - } |
|
842 | 681 | |
843 | - // Fix PHP warning regarding undefined index. |
|
844 | - foreach ( $form['fields'] as &$field) { |
|
682 | + /** |
|
683 | + * |
|
684 | + * Fill-in the saved values into the form inputs |
|
685 | + * |
|
686 | + * @param string $field_content Always empty. |
|
687 | + * @param GF_Field $field |
|
688 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
689 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
690 | + * @param int $form_id Form ID |
|
691 | + * |
|
692 | + * @return mixed |
|
693 | + */ |
|
694 | + function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
695 | + |
|
696 | + // If the form has been submitted, then we don't need to pre-fill the values, |
|
697 | + // Except for fileupload type - run always!! |
|
698 | + if( |
|
699 | + $this->is_edit_entry_submission() && 'fileupload' !== $field->type |
|
700 | + || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
701 | + ) { |
|
702 | + return $field_content; |
|
703 | + } |
|
845 | 704 | |
846 | - // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
847 | - // expects certain field array items to be set. |
|
848 | - foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
849 | - $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
850 | - } |
|
705 | + // Turn on Admin-style display for file upload fields only |
|
706 | + if( 'fileupload' === $field->type ) { |
|
707 | + $_GET['page'] = 'gf_entries'; |
|
708 | + } |
|
709 | + |
|
710 | + // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
711 | + $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
712 | + |
|
713 | + // add categories as choices for Post Category field |
|
714 | + if ( 'post_category' === $field->type ) { |
|
715 | + $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * @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. |
|
720 | + * @param boolean True: override saved values; False: don't override (default) |
|
721 | + * @param $field GF_Field object Gravity Forms field object |
|
722 | + * @since 1.13 |
|
723 | + */ |
|
724 | + $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
725 | + |
|
726 | + // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
727 | + if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
728 | + |
|
729 | + $field_value = array(); |
|
730 | + |
|
731 | + // only accept pre-populated values if the field doesn't have any choice selected. |
|
732 | + $allow_pre_populated = $field->allowsPrepopulate; |
|
733 | + |
|
734 | + foreach ( (array)$field->inputs as $input ) { |
|
735 | + |
|
736 | + $input_id = strval( $input['id'] ); |
|
737 | + |
|
738 | + if ( ! empty( $this->entry[ $input_id ] ) ) { |
|
739 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
740 | + $allow_pre_populated = false; |
|
741 | + } |
|
742 | + |
|
743 | + } |
|
744 | + |
|
745 | + $pre_value = $field->get_value_submission( array(), false ); |
|
746 | + |
|
747 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !empty( $pre_value ) ) ? $field_value : $pre_value; |
|
748 | + |
|
749 | + } else { |
|
750 | + |
|
751 | + $id = intval( $field->id ); |
|
752 | + |
|
753 | + // get pre-populated value if exists |
|
754 | + $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
755 | + |
|
756 | + // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
757 | + // or pre-populated value if not empty and set to override saved value |
|
758 | + $field_value = !empty( $this->entry[ $id ] ) && ! ( $override_saved_value && !empty( $pre_value ) ) ? $this->entry[ $id ] : $pre_value; |
|
759 | + |
|
760 | + // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
761 | + if ( 'post_category' === $field->type && !empty( $field_value ) ) { |
|
762 | + $categories = array(); |
|
763 | + foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
764 | + $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
765 | + } |
|
766 | + $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
767 | + } |
|
768 | + |
|
769 | + } |
|
770 | + |
|
771 | + // if value is empty get the default value if defined |
|
772 | + $field_value = $field->get_value_default_if_empty( $field_value ); |
|
773 | + |
|
774 | + /** |
|
775 | + * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
776 | + * @since 1.11 |
|
777 | + * @param mixed $field_value field value used to populate the input |
|
778 | + * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
779 | + */ |
|
780 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
781 | + |
|
782 | + // Prevent any PHP warnings, like undefined index |
|
783 | + ob_start(); |
|
784 | + |
|
785 | + $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
786 | + |
|
787 | + // If there was output, it's an error |
|
788 | + $warnings = ob_get_clean(); |
|
789 | + |
|
790 | + if( !empty( $warnings ) ) { |
|
791 | + do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
792 | + } |
|
793 | + |
|
794 | + /** |
|
795 | + * Unset hack $_GET['page'] = 'gf_entries' |
|
796 | + * We need the fileupload html field to render with the proper id |
|
797 | + * ( <li id="field_80_16" ... > ) |
|
798 | + */ |
|
799 | + unset( $_GET['page'] ); |
|
800 | + |
|
801 | + return $return; |
|
802 | + } |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * Get the posted values from the edit form submission |
|
807 | + * |
|
808 | + * @hack |
|
809 | + * @uses GFFormsModel::get_field_value() |
|
810 | + * @param mixed $value Existing field value, before edit |
|
811 | + * @param array $lead Gravity Forms entry array |
|
812 | + * @param array $field Gravity Forms field array |
|
813 | + * @return string [description] |
|
814 | + */ |
|
815 | + public function get_field_value( $value, $lead, $field ) { |
|
816 | + |
|
817 | + // The form's not being edited; use the original value |
|
818 | + if( ! $this->is_edit_entry_submission() ) { |
|
819 | + return $value; |
|
820 | + } |
|
851 | 821 | |
852 | - // unset emailConfirmEnabled for email type fields |
|
853 | - /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
822 | + return GFFormsModel::get_field_value( $field, $lead, true ); |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + |
|
827 | + |
|
828 | + // ---- Entry validation |
|
829 | + |
|
830 | + /** |
|
831 | + * Add field keys that Gravity Forms expects. |
|
832 | + * |
|
833 | + * @see GFFormDisplay::validate() |
|
834 | + * @param array $form GF Form |
|
835 | + * @return array Modified GF Form |
|
836 | + */ |
|
837 | + function gform_pre_validation( $form ) { |
|
838 | + |
|
839 | + if( ! $this->verify_nonce() ) { |
|
840 | + return $form; |
|
841 | + } |
|
842 | + |
|
843 | + // Fix PHP warning regarding undefined index. |
|
844 | + foreach ( $form['fields'] as &$field) { |
|
845 | + |
|
846 | + // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
847 | + // expects certain field array items to be set. |
|
848 | + foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
849 | + $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
850 | + } |
|
851 | + |
|
852 | + // unset emailConfirmEnabled for email type fields |
|
853 | + /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
854 | 854 | $field['emailConfirmEnabled'] = ''; |
855 | 855 | }*/ |
856 | 856 | |
857 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
857 | + switch( RGFormsModel::get_input_type( $field ) ) { |
|
858 | 858 | |
859 | - /** |
|
860 | - * 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. |
|
861 | - * |
|
862 | - * 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. |
|
863 | - * |
|
864 | - * @hack |
|
865 | - */ |
|
866 | - case 'fileupload': |
|
867 | - case 'post_image': |
|
859 | + /** |
|
860 | + * 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. |
|
861 | + * |
|
862 | + * 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. |
|
863 | + * |
|
864 | + * @hack |
|
865 | + */ |
|
866 | + case 'fileupload': |
|
867 | + case 'post_image': |
|
868 | 868 | |
869 | - // Set the previous value |
|
870 | - $entry = $this->get_entry(); |
|
869 | + // Set the previous value |
|
870 | + $entry = $this->get_entry(); |
|
871 | 871 | |
872 | - $input_name = 'input_'.$field->id; |
|
873 | - $form_id = $form['id']; |
|
872 | + $input_name = 'input_'.$field->id; |
|
873 | + $form_id = $form['id']; |
|
874 | 874 | |
875 | - $value = NULL; |
|
875 | + $value = NULL; |
|
876 | 876 | |
877 | - // Use the previous entry value as the default. |
|
878 | - if( isset( $entry[ $field->id ] ) ) { |
|
879 | - $value = $entry[ $field->id ]; |
|
880 | - } |
|
877 | + // Use the previous entry value as the default. |
|
878 | + if( isset( $entry[ $field->id ] ) ) { |
|
879 | + $value = $entry[ $field->id ]; |
|
880 | + } |
|
881 | 881 | |
882 | - // If this is a single upload file |
|
883 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
884 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
885 | - $value = $file_path['url']; |
|
882 | + // If this is a single upload file |
|
883 | + if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
884 | + $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
885 | + $value = $file_path['url']; |
|
886 | 886 | |
887 | - } else { |
|
887 | + } else { |
|
888 | 888 | |
889 | - // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
890 | - // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
891 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
889 | + // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
890 | + // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
891 | + $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
892 | 892 | |
893 | - } |
|
893 | + } |
|
894 | 894 | |
895 | - if( rgar($field, "multipleFiles") ) { |
|
895 | + if( rgar($field, "multipleFiles") ) { |
|
896 | 896 | |
897 | - // If there are fresh uploads, process and merge them. |
|
898 | - // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
899 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
897 | + // If there are fresh uploads, process and merge them. |
|
898 | + // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
899 | + if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
900 | 900 | |
901 | - $value = empty( $value ) ? '[]' : $value; |
|
902 | - $value = stripslashes_deep( $value ); |
|
903 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
904 | - } |
|
901 | + $value = empty( $value ) ? '[]' : $value; |
|
902 | + $value = stripslashes_deep( $value ); |
|
903 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
904 | + } |
|
905 | 905 | |
906 | - } else { |
|
906 | + } else { |
|
907 | 907 | |
908 | - // A file already exists when editing an entry |
|
909 | - // We set this to solve issue when file upload fields are required. |
|
910 | - GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
908 | + // A file already exists when editing an entry |
|
909 | + // We set this to solve issue when file upload fields are required. |
|
910 | + GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
911 | 911 | |
912 | - } |
|
912 | + } |
|
913 | 913 | |
914 | - $_POST[ $input_name ] = $value; |
|
914 | + $_POST[ $input_name ] = $value; |
|
915 | 915 | |
916 | - break; |
|
917 | - case 'number': |
|
918 | - // Fix "undefined index" issue at line 1286 in form_display.php |
|
919 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
920 | - $_POST['input_'.$field->id ] = NULL; |
|
921 | - } |
|
922 | - break; |
|
923 | - case 'captcha': |
|
924 | - // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
925 | - $_POST['recaptcha_challenge_field'] = NULL; |
|
926 | - $_POST['recaptcha_response_field'] = NULL; |
|
927 | - break; |
|
928 | - } |
|
916 | + break; |
|
917 | + case 'number': |
|
918 | + // Fix "undefined index" issue at line 1286 in form_display.php |
|
919 | + if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
920 | + $_POST['input_'.$field->id ] = NULL; |
|
921 | + } |
|
922 | + break; |
|
923 | + case 'captcha': |
|
924 | + // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
925 | + $_POST['recaptcha_challenge_field'] = NULL; |
|
926 | + $_POST['recaptcha_response_field'] = NULL; |
|
927 | + break; |
|
928 | + } |
|
929 | 929 | |
930 | - } |
|
930 | + } |
|
931 | 931 | |
932 | - return $form; |
|
933 | - } |
|
932 | + return $form; |
|
933 | + } |
|
934 | 934 | |
935 | 935 | |
936 | - /** |
|
937 | - * Process validation for a edit entry submission |
|
938 | - * |
|
939 | - * Sets the `is_valid` object var |
|
940 | - * |
|
941 | - * @return void |
|
942 | - */ |
|
943 | - function validate() { |
|
936 | + /** |
|
937 | + * Process validation for a edit entry submission |
|
938 | + * |
|
939 | + * Sets the `is_valid` object var |
|
940 | + * |
|
941 | + * @return void |
|
942 | + */ |
|
943 | + function validate() { |
|
944 | 944 | |
945 | - // If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
946 | - if ( class_exists( 'GFUser' ) ) { |
|
947 | - remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
948 | - } |
|
945 | + // If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
946 | + if ( class_exists( 'GFUser' ) ) { |
|
947 | + remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
948 | + } |
|
949 | 949 | |
950 | - /** |
|
951 | - * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
952 | - * You can enter whatever you want! |
|
953 | - * We try validating, and customize the results using `self::custom_validation()` |
|
954 | - */ |
|
955 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
950 | + /** |
|
951 | + * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
952 | + * You can enter whatever you want! |
|
953 | + * We try validating, and customize the results using `self::custom_validation()` |
|
954 | + */ |
|
955 | + add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
956 | 956 | |
957 | - // Needed by the validate funtion |
|
958 | - $failed_validation_page = NULL; |
|
959 | - $field_values = RGForms::post( 'gform_field_values' ); |
|
957 | + // Needed by the validate funtion |
|
958 | + $failed_validation_page = NULL; |
|
959 | + $field_values = RGForms::post( 'gform_field_values' ); |
|
960 | 960 | |
961 | - // Prevent entry limit from running when editing an entry, also |
|
962 | - // prevent form scheduling from preventing editing |
|
963 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
961 | + // Prevent entry limit from running when editing an entry, also |
|
962 | + // prevent form scheduling from preventing editing |
|
963 | + unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
964 | 964 | |
965 | - // Hide fields depending on Edit Entry settings |
|
966 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
965 | + // Hide fields depending on Edit Entry settings |
|
966 | + $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
967 | 967 | |
968 | - $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
968 | + $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
969 | 969 | |
970 | - remove_filter( 'gform_validation_'.$this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
971 | - } |
|
970 | + remove_filter( 'gform_validation_'.$this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
971 | + } |
|
972 | 972 | |
973 | 973 | |
974 | - /** |
|
975 | - * Make validation work for Edit Entry |
|
976 | - * |
|
977 | - * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
978 | - * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
979 | - * fields. This goes through all the fields and if they're an invalid post field, we |
|
980 | - * set them as valid. If there are still issues, we'll return false. |
|
981 | - * |
|
982 | - * @param [type] $validation_results [description] |
|
983 | - * @return [type] [description] |
|
984 | - */ |
|
985 | - function custom_validation( $validation_results ) { |
|
974 | + /** |
|
975 | + * Make validation work for Edit Entry |
|
976 | + * |
|
977 | + * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
978 | + * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
979 | + * fields. This goes through all the fields and if they're an invalid post field, we |
|
980 | + * set them as valid. If there are still issues, we'll return false. |
|
981 | + * |
|
982 | + * @param [type] $validation_results [description] |
|
983 | + * @return [type] [description] |
|
984 | + */ |
|
985 | + function custom_validation( $validation_results ) { |
|
986 | 986 | |
987 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
987 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
988 | 988 | |
989 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
989 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
990 | 990 | |
991 | - $gv_valid = true; |
|
991 | + $gv_valid = true; |
|
992 | 992 | |
993 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
993 | + foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
994 | 994 | |
995 | - $value = RGFormsModel::get_field_value( $field ); |
|
996 | - $field_type = RGFormsModel::get_input_type( $field ); |
|
995 | + $value = RGFormsModel::get_field_value( $field ); |
|
996 | + $field_type = RGFormsModel::get_input_type( $field ); |
|
997 | 997 | |
998 | - // Validate always |
|
999 | - switch ( $field_type ) { |
|
998 | + // Validate always |
|
999 | + switch ( $field_type ) { |
|
1000 | 1000 | |
1001 | 1001 | |
1002 | - case 'fileupload' : |
|
1002 | + case 'fileupload' : |
|
1003 | 1003 | |
1004 | - // in case nothing is uploaded but there are already files saved |
|
1005 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
1006 | - $field->failed_validation = false; |
|
1007 | - unset( $field->validation_message ); |
|
1008 | - } |
|
1004 | + // in case nothing is uploaded but there are already files saved |
|
1005 | + if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
1006 | + $field->failed_validation = false; |
|
1007 | + unset( $field->validation_message ); |
|
1008 | + } |
|
1009 | 1009 | |
1010 | - // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
1011 | - if( rgar( $field, 'maxFiles') && rgar( $field, 'multipleFiles') ) { |
|
1010 | + // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
1011 | + if( rgar( $field, 'maxFiles') && rgar( $field, 'multipleFiles') ) { |
|
1012 | 1012 | |
1013 | - $input_name = 'input_' . $field->id; |
|
1014 | - //uploaded |
|
1015 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
1013 | + $input_name = 'input_' . $field->id; |
|
1014 | + //uploaded |
|
1015 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
1016 | 1016 | |
1017 | - //existent |
|
1018 | - $entry = $this->get_entry(); |
|
1019 | - $value = NULL; |
|
1020 | - if( isset( $entry[ $field->id ] ) ) { |
|
1021 | - $value = json_decode( $entry[ $field->id ], true ); |
|
1022 | - } |
|
1017 | + //existent |
|
1018 | + $entry = $this->get_entry(); |
|
1019 | + $value = NULL; |
|
1020 | + if( isset( $entry[ $field->id ] ) ) { |
|
1021 | + $value = json_decode( $entry[ $field->id ], true ); |
|
1022 | + } |
|
1023 | 1023 | |
1024 | - // count uploaded files and existent entry files |
|
1025 | - $count_files = count( $file_names ) + count( $value ); |
|
1024 | + // count uploaded files and existent entry files |
|
1025 | + $count_files = count( $file_names ) + count( $value ); |
|
1026 | 1026 | |
1027 | - if( $count_files > $field->maxFiles ) { |
|
1028 | - $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
1029 | - $field->failed_validation = 1; |
|
1030 | - $gv_valid = false; |
|
1027 | + if( $count_files > $field->maxFiles ) { |
|
1028 | + $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
1029 | + $field->failed_validation = 1; |
|
1030 | + $gv_valid = false; |
|
1031 | 1031 | |
1032 | - // in case of error make sure the newest upload files are removed from the upload input |
|
1033 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
1034 | - } |
|
1032 | + // in case of error make sure the newest upload files are removed from the upload input |
|
1033 | + GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
1034 | + } |
|
1035 | 1035 | |
1036 | - } |
|
1036 | + } |
|
1037 | 1037 | |
1038 | 1038 | |
1039 | - break; |
|
1039 | + break; |
|
1040 | 1040 | |
1041 | - } |
|
1041 | + } |
|
1042 | 1042 | |
1043 | - // This field has failed validation. |
|
1044 | - if( !empty( $field->failed_validation ) ) { |
|
1043 | + // This field has failed validation. |
|
1044 | + if( !empty( $field->failed_validation ) ) { |
|
1045 | 1045 | |
1046 | - do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
1046 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
1047 | 1047 | |
1048 | - switch ( $field_type ) { |
|
1048 | + switch ( $field_type ) { |
|
1049 | 1049 | |
1050 | - // Captchas don't need to be re-entered. |
|
1051 | - case 'captcha': |
|
1050 | + // Captchas don't need to be re-entered. |
|
1051 | + case 'captcha': |
|
1052 | 1052 | |
1053 | - // Post Image fields aren't editable, so we un-fail them. |
|
1054 | - case 'post_image': |
|
1055 | - $field->failed_validation = false; |
|
1056 | - unset( $field->validation_message ); |
|
1057 | - break; |
|
1053 | + // Post Image fields aren't editable, so we un-fail them. |
|
1054 | + case 'post_image': |
|
1055 | + $field->failed_validation = false; |
|
1056 | + unset( $field->validation_message ); |
|
1057 | + break; |
|
1058 | 1058 | |
1059 | - } |
|
1059 | + } |
|
1060 | 1060 | |
1061 | - // You can't continue inside a switch, so we do it after. |
|
1062 | - if( empty( $field->failed_validation ) ) { |
|
1063 | - continue; |
|
1064 | - } |
|
1061 | + // You can't continue inside a switch, so we do it after. |
|
1062 | + if( empty( $field->failed_validation ) ) { |
|
1063 | + continue; |
|
1064 | + } |
|
1065 | 1065 | |
1066 | - // checks if the No Duplicates option is not validating entry against itself, since |
|
1067 | - // we're editing a stored entry, it would also assume it's a duplicate. |
|
1068 | - if( !empty( $field->noDuplicates ) ) { |
|
1066 | + // checks if the No Duplicates option is not validating entry against itself, since |
|
1067 | + // we're editing a stored entry, it would also assume it's a duplicate. |
|
1068 | + if( !empty( $field->noDuplicates ) ) { |
|
1069 | 1069 | |
1070 | - $entry = $this->get_entry(); |
|
1070 | + $entry = $this->get_entry(); |
|
1071 | 1071 | |
1072 | - // If the value of the entry is the same as the stored value |
|
1073 | - // Then we can assume it's not a duplicate, it's the same. |
|
1074 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
1075 | - //if value submitted was not changed, then don't validate |
|
1076 | - $field->failed_validation = false; |
|
1072 | + // If the value of the entry is the same as the stored value |
|
1073 | + // Then we can assume it's not a duplicate, it's the same. |
|
1074 | + if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
1075 | + //if value submitted was not changed, then don't validate |
|
1076 | + $field->failed_validation = false; |
|
1077 | 1077 | |
1078 | - unset( $field->validation_message ); |
|
1078 | + unset( $field->validation_message ); |
|
1079 | 1079 | |
1080 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
1080 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
1081 | 1081 | |
1082 | - continue; |
|
1083 | - } |
|
1084 | - } |
|
1082 | + continue; |
|
1083 | + } |
|
1084 | + } |
|
1085 | 1085 | |
1086 | - // if here then probably we are facing the validation 'At least one field must be filled out' |
|
1087 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
1088 | - unset( $field->validation_message ); |
|
1089 | - $field->validation_message = false; |
|
1090 | - continue; |
|
1091 | - } |
|
1086 | + // if here then probably we are facing the validation 'At least one field must be filled out' |
|
1087 | + if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
1088 | + unset( $field->validation_message ); |
|
1089 | + $field->validation_message = false; |
|
1090 | + continue; |
|
1091 | + } |
|
1092 | 1092 | |
1093 | - $gv_valid = false; |
|
1093 | + $gv_valid = false; |
|
1094 | 1094 | |
1095 | - } |
|
1095 | + } |
|
1096 | 1096 | |
1097 | - } |
|
1097 | + } |
|
1098 | 1098 | |
1099 | - $validation_results['is_valid'] = $gv_valid; |
|
1099 | + $validation_results['is_valid'] = $gv_valid; |
|
1100 | 1100 | |
1101 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
1101 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
1102 | 1102 | |
1103 | - // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
1104 | - $this->form_after_validation = $validation_results['form']; |
|
1103 | + // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
1104 | + $this->form_after_validation = $validation_results['form']; |
|
1105 | 1105 | |
1106 | - return $validation_results; |
|
1107 | - } |
|
1106 | + return $validation_results; |
|
1107 | + } |
|
1108 | 1108 | |
1109 | 1109 | |
1110 | - /** |
|
1111 | - * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
1112 | - * Get the current entry and set it if it's not yet set. |
|
1113 | - * @return array Gravity Forms entry array |
|
1114 | - */ |
|
1115 | - private function get_entry() { |
|
1110 | + /** |
|
1111 | + * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
1112 | + * Get the current entry and set it if it's not yet set. |
|
1113 | + * @return array Gravity Forms entry array |
|
1114 | + */ |
|
1115 | + private function get_entry() { |
|
1116 | 1116 | |
1117 | - if( empty( $this->entry ) ) { |
|
1118 | - // Get the database value of the entry that's being edited |
|
1119 | - $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
1120 | - } |
|
1117 | + if( empty( $this->entry ) ) { |
|
1118 | + // Get the database value of the entry that's being edited |
|
1119 | + $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
1120 | + } |
|
1121 | 1121 | |
1122 | - return $this->entry; |
|
1123 | - } |
|
1122 | + return $this->entry; |
|
1123 | + } |
|
1124 | 1124 | |
1125 | 1125 | |
1126 | 1126 | |
1127 | - // --- Filters |
|
1127 | + // --- Filters |
|
1128 | 1128 | |
1129 | - /** |
|
1130 | - * Get the Edit Entry fields as configured in the View |
|
1131 | - * |
|
1132 | - * @since 1.8 |
|
1133 | - * |
|
1134 | - * @param int $view_id |
|
1135 | - * |
|
1136 | - * @return array Array of fields that are configured in the Edit tab in the Admin |
|
1137 | - */ |
|
1138 | - private function get_configured_edit_fields( $form, $view_id ) { |
|
1129 | + /** |
|
1130 | + * Get the Edit Entry fields as configured in the View |
|
1131 | + * |
|
1132 | + * @since 1.8 |
|
1133 | + * |
|
1134 | + * @param int $view_id |
|
1135 | + * |
|
1136 | + * @return array Array of fields that are configured in the Edit tab in the Admin |
|
1137 | + */ |
|
1138 | + private function get_configured_edit_fields( $form, $view_id ) { |
|
1139 | 1139 | |
1140 | - // Get all fields for form |
|
1141 | - $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
1140 | + // Get all fields for form |
|
1141 | + $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
1142 | 1142 | |
1143 | - // If edit tab not yet configured, show all fields |
|
1144 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
1143 | + // If edit tab not yet configured, show all fields |
|
1144 | + $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
1145 | 1145 | |
1146 | - // Show hidden fields as text fields |
|
1147 | - $form = $this->fix_hidden_fields( $form ); |
|
1146 | + // Show hidden fields as text fields |
|
1147 | + $form = $this->fix_hidden_fields( $form ); |
|
1148 | 1148 | |
1149 | - // Hide fields depending on admin settings |
|
1150 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
1149 | + // Hide fields depending on admin settings |
|
1150 | + $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
1151 | 1151 | |
1152 | - // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
1153 | - $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
1152 | + // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
1153 | + $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
1154 | 1154 | |
1155 | - return $fields; |
|
1156 | - } |
|
1155 | + return $fields; |
|
1156 | + } |
|
1157 | 1157 | |
1158 | 1158 | /** |
1159 | 1159 | * @since 1.9.2 |
@@ -1177,364 +1177,364 @@ discard block |
||
1177 | 1177 | } |
1178 | 1178 | |
1179 | 1179 | |
1180 | - /** |
|
1181 | - * Filter area fields based on specified conditions |
|
1182 | - * |
|
1183 | - * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
1184 | - * @access private |
|
1185 | - * @param GF_Field[] $fields |
|
1186 | - * @param array $configured_fields |
|
1187 | - * @since 1.5 |
|
1188 | - * @return array $fields |
|
1189 | - */ |
|
1190 | - private function filter_fields( $fields, $configured_fields ) { |
|
1191 | - |
|
1192 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
1193 | - return $fields; |
|
1194 | - } |
|
1195 | - |
|
1196 | - $edit_fields = array(); |
|
1197 | - |
|
1198 | - $field_type_blacklist = array( |
|
1199 | - 'page', |
|
1200 | - ); |
|
1201 | - |
|
1202 | - /** |
|
1203 | - * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
1204 | - * @since 1.9.1 |
|
1205 | - * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
1206 | - */ |
|
1207 | - $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
1208 | - |
|
1209 | - if( $hide_product_fields ) { |
|
1210 | - $field_type_blacklist[] = 'option'; |
|
1211 | - $field_type_blacklist[] = 'quantity'; |
|
1212 | - $field_type_blacklist[] = 'product'; |
|
1213 | - $field_type_blacklist[] = 'total'; |
|
1214 | - $field_type_blacklist[] = 'shipping'; |
|
1215 | - $field_type_blacklist[] = 'calculation'; |
|
1216 | - } |
|
1217 | - |
|
1218 | - // First, remove blacklist |
|
1219 | - foreach ( $fields as $key => $field ) { |
|
1220 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
1221 | - unset( $fields[ $key ] ); |
|
1222 | - } |
|
1223 | - } |
|
1224 | - |
|
1225 | - // The Edit tab has not been configured, so we return all fields by default. |
|
1226 | - if( empty( $configured_fields ) ) { |
|
1227 | - return $fields; |
|
1228 | - } |
|
1229 | - |
|
1230 | - // The edit tab has been configured, so we loop through to configured settings |
|
1231 | - foreach ( $configured_fields as $configured_field ) { |
|
1232 | - |
|
1233 | - /** @var GF_Field $field */ |
|
1234 | - foreach ( $fields as $field ) { |
|
1235 | - |
|
1236 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
1237 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
1238 | - break; |
|
1239 | - } |
|
1240 | - |
|
1241 | - } |
|
1242 | - |
|
1243 | - } |
|
1244 | - |
|
1245 | - return $edit_fields; |
|
1246 | - |
|
1247 | - } |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Override GF Form field properties with the ones defined on the View |
|
1251 | - * @param GF_Field $field GF Form field object |
|
1252 | - * @param array $setting GV field options |
|
1253 | - * @since 1.5 |
|
1254 | - * @return array |
|
1255 | - */ |
|
1256 | - private function merge_field_properties( $field, $field_setting ) { |
|
1257 | - |
|
1258 | - $return_field = $field; |
|
1259 | - |
|
1260 | - if( empty( $field_setting['show_label'] ) ) { |
|
1261 | - $return_field->label = ''; |
|
1262 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
1263 | - $return_field->label = $field_setting['custom_label']; |
|
1264 | - } |
|
1265 | - |
|
1266 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
1267 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * Normalize page numbers - avoid conflicts with page validation |
|
1272 | - * @since 1.6 |
|
1273 | - */ |
|
1274 | - $return_field->pageNumber = 1; |
|
1275 | - |
|
1276 | - return $return_field; |
|
1277 | - |
|
1278 | - } |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
1282 | - * |
|
1283 | - * @since 1.9.1 |
|
1284 | - * |
|
1285 | - * @param array|GF_Field[] $fields Gravity Forms form fields |
|
1286 | - * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
1287 | - * @param array $form GF Form array |
|
1288 | - * @param int $view_id View ID |
|
1289 | - * |
|
1290 | - * @return array Possibly modified form array |
|
1291 | - */ |
|
1292 | - function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
1293 | - |
|
1294 | - /** |
|
1295 | - * @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 |
|
1296 | - * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
1297 | - * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
1298 | - * @since 1.9.1 |
|
1299 | - * @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. |
|
1300 | - * @param array $form GF Form array |
|
1301 | - * @param int $view_id View ID |
|
1302 | - */ |
|
1303 | - $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
1304 | - |
|
1305 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
1306 | - return $fields; |
|
1307 | - } |
|
1308 | - |
|
1309 | - foreach( $fields as &$field ) { |
|
1310 | - $field->adminOnly = false; |
|
1311 | - } |
|
1312 | - |
|
1313 | - return $fields; |
|
1314 | - } |
|
1315 | - |
|
1316 | - // --- Conditional Logic |
|
1317 | - |
|
1318 | - /** |
|
1319 | - * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
1320 | - * |
|
1321 | - * @since 1.9 |
|
1322 | - * |
|
1323 | - * @param array $form Gravity Forms form |
|
1324 | - * @return array Modified form, if not using Conditional Logic |
|
1325 | - */ |
|
1326 | - function filter_conditional_logic( $form ) { |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
1330 | - * @since 1.9 |
|
1331 | - * @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 |
|
1332 | - * @param array $form Gravity Forms form |
|
1333 | - */ |
|
1334 | - $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
1335 | - |
|
1336 | - if( $use_conditional_logic ) { |
|
1337 | - return $form; |
|
1338 | - } |
|
1339 | - |
|
1340 | - foreach( $form['fields'] as &$field ) { |
|
1341 | - /* @var GF_Field $field */ |
|
1342 | - $field->conditionalLogic = null; |
|
1343 | - } |
|
1344 | - |
|
1345 | - unset( $form['button']['conditionalLogic'] ); |
|
1346 | - |
|
1347 | - return $form; |
|
1348 | - |
|
1349 | - } |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
1353 | - * |
|
1354 | - * @since 1.9 |
|
1355 | - * |
|
1356 | - * @param $has_conditional_logic |
|
1357 | - * @param $form |
|
1358 | - * @return mixed|void |
|
1359 | - */ |
|
1360 | - function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
1361 | - |
|
1362 | - if( ! $this->is_edit_entry() ) { |
|
1363 | - return $has_conditional_logic; |
|
1364 | - } |
|
1365 | - |
|
1366 | - return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
1367 | - |
|
1368 | - } |
|
1369 | - |
|
1370 | - |
|
1371 | - // --- User checks and nonces |
|
1372 | - |
|
1373 | - /** |
|
1374 | - * Check if the user can edit the entry |
|
1375 | - * |
|
1376 | - * - Is the nonce valid? |
|
1377 | - * - Does the user have the right caps for the entry |
|
1378 | - * - Is the entry in the trash? |
|
1379 | - * |
|
1380 | - * @todo Move to GVCommon |
|
1381 | - * |
|
1382 | - * @param boolean $echo Show error messages in the form? |
|
1383 | - * @return boolean True: can edit form. False: nope. |
|
1384 | - */ |
|
1385 | - function user_can_edit_entry( $echo = false ) { |
|
1386 | - |
|
1387 | - $error = NULL; |
|
1388 | - |
|
1389 | - /** |
|
1390 | - * 1. Permalinks are turned off |
|
1391 | - * 2. There are two entries embedded using oEmbed |
|
1392 | - * 3. One of the entries has just been saved |
|
1393 | - */ |
|
1394 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
1395 | - |
|
1396 | - $error = true; |
|
1397 | - |
|
1398 | - } |
|
1180 | + /** |
|
1181 | + * Filter area fields based on specified conditions |
|
1182 | + * |
|
1183 | + * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
1184 | + * @access private |
|
1185 | + * @param GF_Field[] $fields |
|
1186 | + * @param array $configured_fields |
|
1187 | + * @since 1.5 |
|
1188 | + * @return array $fields |
|
1189 | + */ |
|
1190 | + private function filter_fields( $fields, $configured_fields ) { |
|
1399 | 1191 | |
1400 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
1192 | + if( empty( $fields ) || !is_array( $fields ) ) { |
|
1193 | + return $fields; |
|
1194 | + } |
|
1401 | 1195 | |
1402 | - $error = true; |
|
1196 | + $edit_fields = array(); |
|
1197 | + |
|
1198 | + $field_type_blacklist = array( |
|
1199 | + 'page', |
|
1200 | + ); |
|
1201 | + |
|
1202 | + /** |
|
1203 | + * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
1204 | + * @since 1.9.1 |
|
1205 | + * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
1206 | + */ |
|
1207 | + $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
1208 | + |
|
1209 | + if( $hide_product_fields ) { |
|
1210 | + $field_type_blacklist[] = 'option'; |
|
1211 | + $field_type_blacklist[] = 'quantity'; |
|
1212 | + $field_type_blacklist[] = 'product'; |
|
1213 | + $field_type_blacklist[] = 'total'; |
|
1214 | + $field_type_blacklist[] = 'shipping'; |
|
1215 | + $field_type_blacklist[] = 'calculation'; |
|
1216 | + } |
|
1403 | 1217 | |
1404 | - } elseif( ! $this->verify_nonce() ) { |
|
1218 | + // First, remove blacklist |
|
1219 | + foreach ( $fields as $key => $field ) { |
|
1220 | + if( in_array( $field->type, $field_type_blacklist ) ) { |
|
1221 | + unset( $fields[ $key ] ); |
|
1222 | + } |
|
1223 | + } |
|
1405 | 1224 | |
1406 | - /** |
|
1407 | - * If the Entry is embedded, there may be two entries on the same page. |
|
1408 | - * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
1409 | - */ |
|
1410 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
1411 | - $error = true; |
|
1412 | - } else { |
|
1413 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
1414 | - } |
|
1225 | + // The Edit tab has not been configured, so we return all fields by default. |
|
1226 | + if( empty( $configured_fields ) ) { |
|
1227 | + return $fields; |
|
1228 | + } |
|
1415 | 1229 | |
1416 | - } |
|
1230 | + // The edit tab has been configured, so we loop through to configured settings |
|
1231 | + foreach ( $configured_fields as $configured_field ) { |
|
1417 | 1232 | |
1418 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
1419 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
1420 | - } |
|
1233 | + /** @var GF_Field $field */ |
|
1234 | + foreach ( $fields as $field ) { |
|
1421 | 1235 | |
1422 | - if( $this->entry['status'] === 'trash' ) { |
|
1423 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
1424 | - } |
|
1236 | + if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
1237 | + $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
1238 | + break; |
|
1239 | + } |
|
1425 | 1240 | |
1426 | - // No errors; everything's fine here! |
|
1427 | - if( empty( $error ) ) { |
|
1428 | - return true; |
|
1429 | - } |
|
1241 | + } |
|
1430 | 1242 | |
1431 | - if( $echo && $error !== true ) { |
|
1243 | + } |
|
1432 | 1244 | |
1433 | - $error = esc_html( $error ); |
|
1245 | + return $edit_fields; |
|
1434 | 1246 | |
1435 | - /** |
|
1436 | - * @since 1.9 |
|
1437 | - */ |
|
1438 | - if ( ! empty( $this->entry ) ) { |
|
1439 | - $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;" ) ); |
|
1440 | - } |
|
1247 | + } |
|
1441 | 1248 | |
1442 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
1443 | - } |
|
1249 | + /** |
|
1250 | + * Override GF Form field properties with the ones defined on the View |
|
1251 | + * @param GF_Field $field GF Form field object |
|
1252 | + * @param array $setting GV field options |
|
1253 | + * @since 1.5 |
|
1254 | + * @return array |
|
1255 | + */ |
|
1256 | + private function merge_field_properties( $field, $field_setting ) { |
|
1444 | 1257 | |
1445 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
1258 | + $return_field = $field; |
|
1446 | 1259 | |
1447 | - return false; |
|
1448 | - } |
|
1260 | + if( empty( $field_setting['show_label'] ) ) { |
|
1261 | + $return_field->label = ''; |
|
1262 | + } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
1263 | + $return_field->label = $field_setting['custom_label']; |
|
1264 | + } |
|
1449 | 1265 | |
1266 | + if( !empty( $field_setting['custom_class'] ) ) { |
|
1267 | + $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
1268 | + } |
|
1450 | 1269 | |
1451 | - /** |
|
1452 | - * Check whether a field is editable by the current user, and optionally display an error message |
|
1453 | - * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
1454 | - * @param array $field Field or field settings array |
|
1455 | - * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
1456 | - * @return boolean True: user can edit the current field; False: nope, they can't. |
|
1457 | - */ |
|
1458 | - private function user_can_edit_field( $field, $echo = false ) { |
|
1270 | + /** |
|
1271 | + * Normalize page numbers - avoid conflicts with page validation |
|
1272 | + * @since 1.6 |
|
1273 | + */ |
|
1274 | + $return_field->pageNumber = 1; |
|
1459 | 1275 | |
1460 | - $error = NULL; |
|
1276 | + return $return_field; |
|
1461 | 1277 | |
1462 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
1463 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
1464 | - } |
|
1278 | + } |
|
1465 | 1279 | |
1466 | - // No errors; everything's fine here! |
|
1467 | - if( empty( $error ) ) { |
|
1468 | - return true; |
|
1469 | - } |
|
1280 | + /** |
|
1281 | + * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
1282 | + * |
|
1283 | + * @since 1.9.1 |
|
1284 | + * |
|
1285 | + * @param array|GF_Field[] $fields Gravity Forms form fields |
|
1286 | + * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
1287 | + * @param array $form GF Form array |
|
1288 | + * @param int $view_id View ID |
|
1289 | + * |
|
1290 | + * @return array Possibly modified form array |
|
1291 | + */ |
|
1292 | + function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
1293 | + |
|
1294 | + /** |
|
1295 | + * @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 |
|
1296 | + * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
1297 | + * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
1298 | + * @since 1.9.1 |
|
1299 | + * @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. |
|
1300 | + * @param array $form GF Form array |
|
1301 | + * @param int $view_id View ID |
|
1302 | + */ |
|
1303 | + $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
1304 | + |
|
1305 | + if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
1306 | + return $fields; |
|
1307 | + } |
|
1470 | 1308 | |
1471 | - if( $echo ) { |
|
1472 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
1473 | - } |
|
1474 | - |
|
1475 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
1309 | + foreach( $fields as &$field ) { |
|
1310 | + $field->adminOnly = false; |
|
1311 | + } |
|
1476 | 1312 | |
1477 | - return false; |
|
1313 | + return $fields; |
|
1314 | + } |
|
1478 | 1315 | |
1479 | - } |
|
1316 | + // --- Conditional Logic |
|
1480 | 1317 | |
1318 | + /** |
|
1319 | + * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
1320 | + * |
|
1321 | + * @since 1.9 |
|
1322 | + * |
|
1323 | + * @param array $form Gravity Forms form |
|
1324 | + * @return array Modified form, if not using Conditional Logic |
|
1325 | + */ |
|
1326 | + function filter_conditional_logic( $form ) { |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
1330 | + * @since 1.9 |
|
1331 | + * @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 |
|
1332 | + * @param array $form Gravity Forms form |
|
1333 | + */ |
|
1334 | + $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
1335 | + |
|
1336 | + if( $use_conditional_logic ) { |
|
1337 | + return $form; |
|
1338 | + } |
|
1481 | 1339 | |
1482 | - /** |
|
1483 | - * checks if user has permissions to edit a specific field |
|
1484 | - * |
|
1485 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
1486 | - * |
|
1487 | - * @param [type] $field [description] |
|
1488 | - * @return bool |
|
1489 | - */ |
|
1490 | - private function check_user_cap_edit_field( $field ) { |
|
1340 | + foreach( $form['fields'] as &$field ) { |
|
1341 | + /* @var GF_Field $field */ |
|
1342 | + $field->conditionalLogic = null; |
|
1343 | + } |
|
1491 | 1344 | |
1492 | - // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
1493 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
1494 | - return true; |
|
1495 | - } |
|
1345 | + unset( $form['button']['conditionalLogic'] ); |
|
1496 | 1346 | |
1497 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
1347 | + return $form; |
|
1498 | 1348 | |
1499 | - // If the field has custom editing capaibilities set, check those |
|
1500 | - if( $field_cap ) { |
|
1501 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
1502 | - } |
|
1503 | - |
|
1504 | - return false; |
|
1505 | - } |
|
1349 | + } |
|
1506 | 1350 | |
1351 | + /** |
|
1352 | + * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
1353 | + * |
|
1354 | + * @since 1.9 |
|
1355 | + * |
|
1356 | + * @param $has_conditional_logic |
|
1357 | + * @param $form |
|
1358 | + * @return mixed|void |
|
1359 | + */ |
|
1360 | + function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
1361 | + |
|
1362 | + if( ! $this->is_edit_entry() ) { |
|
1363 | + return $has_conditional_logic; |
|
1364 | + } |
|
1365 | + |
|
1366 | + return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
1367 | + |
|
1368 | + } |
|
1369 | + |
|
1370 | + |
|
1371 | + // --- User checks and nonces |
|
1372 | + |
|
1373 | + /** |
|
1374 | + * Check if the user can edit the entry |
|
1375 | + * |
|
1376 | + * - Is the nonce valid? |
|
1377 | + * - Does the user have the right caps for the entry |
|
1378 | + * - Is the entry in the trash? |
|
1379 | + * |
|
1380 | + * @todo Move to GVCommon |
|
1381 | + * |
|
1382 | + * @param boolean $echo Show error messages in the form? |
|
1383 | + * @return boolean True: can edit form. False: nope. |
|
1384 | + */ |
|
1385 | + function user_can_edit_entry( $echo = false ) { |
|
1386 | + |
|
1387 | + $error = NULL; |
|
1388 | + |
|
1389 | + /** |
|
1390 | + * 1. Permalinks are turned off |
|
1391 | + * 2. There are two entries embedded using oEmbed |
|
1392 | + * 3. One of the entries has just been saved |
|
1393 | + */ |
|
1394 | + if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
1395 | + |
|
1396 | + $error = true; |
|
1397 | + |
|
1398 | + } |
|
1399 | + |
|
1400 | + if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
1401 | + |
|
1402 | + $error = true; |
|
1403 | + |
|
1404 | + } elseif( ! $this->verify_nonce() ) { |
|
1405 | + |
|
1406 | + /** |
|
1407 | + * If the Entry is embedded, there may be two entries on the same page. |
|
1408 | + * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
1409 | + */ |
|
1410 | + if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
1411 | + $error = true; |
|
1412 | + } else { |
|
1413 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
1414 | + } |
|
1415 | + |
|
1416 | + } |
|
1417 | + |
|
1418 | + if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
1419 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
1420 | + } |
|
1421 | + |
|
1422 | + if( $this->entry['status'] === 'trash' ) { |
|
1423 | + $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
1424 | + } |
|
1425 | + |
|
1426 | + // No errors; everything's fine here! |
|
1427 | + if( empty( $error ) ) { |
|
1428 | + return true; |
|
1429 | + } |
|
1430 | + |
|
1431 | + if( $echo && $error !== true ) { |
|
1432 | + |
|
1433 | + $error = esc_html( $error ); |
|
1434 | + |
|
1435 | + /** |
|
1436 | + * @since 1.9 |
|
1437 | + */ |
|
1438 | + if ( ! empty( $this->entry ) ) { |
|
1439 | + $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;" ) ); |
|
1440 | + } |
|
1441 | + |
|
1442 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
1443 | + } |
|
1507 | 1444 | |
1508 | - /** |
|
1509 | - * Is the current nonce valid for editing the entry? |
|
1510 | - * @return boolean |
|
1511 | - */ |
|
1512 | - public function verify_nonce() { |
|
1445 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
1513 | 1446 | |
1514 | - // Verify form submitted for editing single |
|
1515 | - if( $this->is_edit_entry_submission() ) { |
|
1516 | - $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
1517 | - } |
|
1447 | + return false; |
|
1448 | + } |
|
1449 | + |
|
1450 | + |
|
1451 | + /** |
|
1452 | + * Check whether a field is editable by the current user, and optionally display an error message |
|
1453 | + * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
1454 | + * @param array $field Field or field settings array |
|
1455 | + * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
1456 | + * @return boolean True: user can edit the current field; False: nope, they can't. |
|
1457 | + */ |
|
1458 | + private function user_can_edit_field( $field, $echo = false ) { |
|
1459 | + |
|
1460 | + $error = NULL; |
|
1461 | + |
|
1462 | + if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
1463 | + $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
1464 | + } |
|
1465 | + |
|
1466 | + // No errors; everything's fine here! |
|
1467 | + if( empty( $error ) ) { |
|
1468 | + return true; |
|
1469 | + } |
|
1518 | 1470 | |
1519 | - // Verify |
|
1520 | - else if( ! $this->is_edit_entry() ) { |
|
1521 | - $valid = false; |
|
1522 | - } |
|
1471 | + if( $echo ) { |
|
1472 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
1473 | + } |
|
1474 | + |
|
1475 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
1476 | + |
|
1477 | + return false; |
|
1478 | + |
|
1479 | + } |
|
1523 | 1480 | |
1524 | - else { |
|
1525 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
1526 | - } |
|
1527 | 1481 | |
1528 | - /** |
|
1529 | - * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
1530 | - * @since 1.13 |
|
1531 | - * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
1532 | - * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
1533 | - */ |
|
1534 | - $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
1482 | + /** |
|
1483 | + * checks if user has permissions to edit a specific field |
|
1484 | + * |
|
1485 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
1486 | + * |
|
1487 | + * @param [type] $field [description] |
|
1488 | + * @return bool |
|
1489 | + */ |
|
1490 | + private function check_user_cap_edit_field( $field ) { |
|
1535 | 1491 | |
1536 | - return $valid; |
|
1537 | - } |
|
1492 | + // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
1493 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
1494 | + return true; |
|
1495 | + } |
|
1496 | + |
|
1497 | + $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
1498 | + |
|
1499 | + // If the field has custom editing capaibilities set, check those |
|
1500 | + if( $field_cap ) { |
|
1501 | + return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
1502 | + } |
|
1503 | + |
|
1504 | + return false; |
|
1505 | + } |
|
1506 | + |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * Is the current nonce valid for editing the entry? |
|
1510 | + * @return boolean |
|
1511 | + */ |
|
1512 | + public function verify_nonce() { |
|
1513 | + |
|
1514 | + // Verify form submitted for editing single |
|
1515 | + if( $this->is_edit_entry_submission() ) { |
|
1516 | + $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
1517 | + } |
|
1518 | + |
|
1519 | + // Verify |
|
1520 | + else if( ! $this->is_edit_entry() ) { |
|
1521 | + $valid = false; |
|
1522 | + } |
|
1523 | + |
|
1524 | + else { |
|
1525 | + $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
1526 | + } |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
1530 | + * @since 1.13 |
|
1531 | + * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
1532 | + * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
1533 | + */ |
|
1534 | + $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
1535 | + |
|
1536 | + return $valid; |
|
1537 | + } |
|
1538 | 1538 | |
1539 | 1539 | |
1540 | 1540 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @copyright Copyright 2014, Katz Web Services, Inc. |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'WPINC' ) ) { |
|
12 | +if (!defined('WPINC')) { |
|
13 | 13 | die; |
14 | 14 | } |
15 | 15 | |
@@ -84,30 +84,30 @@ discard block |
||
84 | 84 | */ |
85 | 85 | var $is_valid = NULL; |
86 | 86 | |
87 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
87 | + function __construct(GravityView_Edit_Entry $loader) { |
|
88 | 88 | $this->loader = $loader; |
89 | 89 | } |
90 | 90 | |
91 | 91 | function load() { |
92 | 92 | |
93 | 93 | /** @define "GRAVITYVIEW_DIR" "../../../" */ |
94 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
94 | + include_once(GRAVITYVIEW_DIR.'includes/class-admin-approve-entries.php'); |
|
95 | 95 | |
96 | 96 | // Stop Gravity Forms processing what is ours! |
97 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
97 | + add_filter('wp', array($this, 'prevent_maybe_process_form'), 8); |
|
98 | 98 | |
99 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
99 | + add_filter('gravityview_is_edit_entry', array($this, 'is_edit_entry')); |
|
100 | 100 | |
101 | - add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
101 | + add_action('gravityview_edit_entry', array($this, 'init')); |
|
102 | 102 | |
103 | 103 | // Disable conditional logic if needed (since 1.9) |
104 | - add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
104 | + add_filter('gform_has_conditional_logic', array($this, 'manage_conditional_logic'), 10, 2); |
|
105 | 105 | |
106 | 106 | // Make sure GF doesn't validate max files (since 1.9) |
107 | - add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
107 | + add_filter('gform_plupload_settings', array($this, 'modify_fileupload_settings'), 10, 3); |
|
108 | 108 | |
109 | 109 | // Add fields expected by GFFormDisplay::validate() |
110 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
110 | + add_filter('gform_pre_validation', array($this, 'gform_pre_validation')); |
|
111 | 111 | |
112 | 112 | } |
113 | 113 | |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | */ |
121 | 121 | function prevent_maybe_process_form() { |
122 | 122 | |
123 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
123 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html(print_r($_POST, true))); |
|
124 | 124 | |
125 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
126 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
125 | + if ($this->is_edit_entry_submission() && $this->verify_nonce()) { |
|
126 | + remove_action('wp', array('RGForms', 'maybe_process_form'), 9); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function is_edit_entry() { |
135 | 135 | |
136 | - $gf_page = ( 'entry' === RGForms::get( 'view' ) ); |
|
136 | + $gf_page = ('entry' === RGForms::get('view')); |
|
137 | 137 | |
138 | - return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); |
|
138 | + return ($gf_page && isset($_GET['edit']) || RGForms::post('action') === 'update'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return boolean |
145 | 145 | */ |
146 | 146 | public function is_edit_entry_submission() { |
147 | - return !empty( $_POST[ self::$nonce_field ] ); |
|
147 | + return !empty($_POST[self::$nonce_field]); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $this->form_id = $gravityview_view->getFormId(); |
163 | 163 | $this->view_id = $gravityview_view->getViewId(); |
164 | 164 | |
165 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
165 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key($this->view_id, $this->form_id, $this->entry['id']); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
@@ -174,20 +174,20 @@ discard block |
||
174 | 174 | * @param GravityView_View_Data $gv_data GravityView Data object |
175 | 175 | * @return void |
176 | 176 | */ |
177 | - function init( $gv_data ) { |
|
177 | + function init($gv_data) { |
|
178 | 178 | |
179 | - require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
180 | - require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
179 | + require_once(GFCommon::get_base_path().'/form_display.php'); |
|
180 | + require_once(GFCommon::get_base_path().'/entry_detail.php'); |
|
181 | 181 | |
182 | 182 | $this->setup_vars(); |
183 | 183 | |
184 | 184 | // Multiple Views embedded, don't proceed if nonce fails |
185 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
185 | + if ($gv_data->has_multiple_views() && !wp_verify_nonce($_GET['edit'], self::$nonce_key)) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | 189 | // Sorry, you're not allowed here. |
190 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
190 | + if (false === $this->user_can_edit_entry(true)) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
@@ -207,12 +207,12 @@ discard block |
||
207 | 207 | function print_scripts() { |
208 | 208 | $gravityview_view = GravityView_View::getInstance(); |
209 | 209 | |
210 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
210 | + wp_register_script('gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array('jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view')); |
|
211 | 211 | |
212 | 212 | GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
213 | 213 | |
214 | 214 | // Sack is required for images |
215 | - wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
215 | + wp_print_scripts(array('sack', 'gform_gravityforms')); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | |
@@ -221,32 +221,32 @@ discard block |
||
221 | 221 | */ |
222 | 222 | function process_save() { |
223 | 223 | |
224 | - if( empty( $_POST ) ) { |
|
224 | + if (empty($_POST)) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | 228 | // Make sure the entry, view, and form IDs are all correct |
229 | 229 | $valid = $this->verify_nonce(); |
230 | 230 | |
231 | - if( !$valid ) { |
|
232 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
231 | + if (!$valid) { |
|
232 | + do_action('gravityview_log_error', __METHOD__.' Nonce validation failed.'); |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 | |
236 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
237 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
236 | + if ($this->entry['id'] !== $_POST['lid']) { |
|
237 | + do_action('gravityview_log_error', __METHOD__.' Entry ID did not match posted entry ID.'); |
|
238 | 238 | return; |
239 | 239 | } |
240 | 240 | |
241 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
241 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html(print_r($_POST, true))); |
|
242 | 242 | |
243 | - $this->process_save_process_files( $this->form_id ); |
|
243 | + $this->process_save_process_files($this->form_id); |
|
244 | 244 | |
245 | 245 | $this->validate(); |
246 | 246 | |
247 | - if( $this->is_valid ) { |
|
247 | + if ($this->is_valid) { |
|
248 | 248 | |
249 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
249 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.'); |
|
250 | 250 | |
251 | 251 | /** |
252 | 252 | * @hack This step is needed to unset the adminOnly from form fields |
@@ -256,13 +256,13 @@ discard block |
||
256 | 256 | /** |
257 | 257 | * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
258 | 258 | */ |
259 | - unset( $_GET['page'] ); |
|
259 | + unset($_GET['page']); |
|
260 | 260 | |
261 | - GFFormsModel::save_lead( $form, $this->entry ); |
|
261 | + GFFormsModel::save_lead($form, $this->entry); |
|
262 | 262 | |
263 | 263 | // If there's a post associated with the entry, process post fields |
264 | - if( !empty( $this->entry['post_id'] ) ) { |
|
265 | - $this->maybe_update_post_fields( $form ); |
|
264 | + if (!empty($this->entry['post_id'])) { |
|
265 | + $this->maybe_update_post_fields($form); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | // Perform actions normally performed after updating a lead |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @param array $form Gravity Forms form array |
274 | 274 | * @param string $entry_id Numeric ID of the entry that was updated |
275 | 275 | */ |
276 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
276 | + do_action('gravityview/edit_entry/after_update', $this->form, $this->entry['id']); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | } // process_save |
@@ -286,15 +286,15 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @param int $form_id |
288 | 288 | */ |
289 | - function process_save_process_files( $form_id ) { |
|
289 | + function process_save_process_files($form_id) { |
|
290 | 290 | |
291 | 291 | //Loading files that have been uploaded to temp folder |
292 | - $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
293 | - if ( ! is_array( $files ) ) { |
|
292 | + $files = GFCommon::json_decode(stripslashes(RGForms::post('gform_uploaded_files'))); |
|
293 | + if (!is_array($files)) { |
|
294 | 294 | $files = array(); |
295 | 295 | } |
296 | 296 | |
297 | - RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
297 | + RGFormsModel::$uploaded_files[$form_id] = $files; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @param $instance |
307 | 307 | * @return mixed |
308 | 308 | */ |
309 | - public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
310 | - if( ! $this->is_edit_entry() ) { |
|
309 | + public function modify_fileupload_settings($plupload_init, $form_id, $instance) { |
|
310 | + if (!$this->is_edit_entry()) { |
|
311 | 311 | return $plupload_init; |
312 | 312 | } |
313 | 313 | |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | private function form_prepare_for_save() { |
325 | 325 | $form = $this->form; |
326 | 326 | |
327 | - foreach( $form['fields'] as &$field ) { |
|
327 | + foreach ($form['fields'] as &$field) { |
|
328 | 328 | |
329 | 329 | $field->adminOnly = false; |
330 | 330 | |
331 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
332 | - foreach( $field->inputs as $key => $input ) { |
|
333 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
331 | + if (isset($field->inputs) && is_array($field->inputs)) { |
|
332 | + foreach ($field->inputs as $key => $input) { |
|
333 | + $field->inputs[$key]['id'] = (string)$input['id']; |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |
@@ -346,39 +346,39 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @return void |
348 | 348 | */ |
349 | - function maybe_update_post_fields( $form ) { |
|
349 | + function maybe_update_post_fields($form) { |
|
350 | 350 | |
351 | 351 | $post_id = $this->entry['post_id']; |
352 | 352 | |
353 | 353 | // Security check |
354 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
355 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
354 | + if (false === GVCommon::has_cap('edit_post', $post_id)) { |
|
355 | + do_action('gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id); |
|
356 | 356 | return; |
357 | 357 | } |
358 | 358 | |
359 | 359 | $update_entry = false; |
360 | 360 | |
361 | - $updated_post = $original_post = get_post( $post_id ); |
|
361 | + $updated_post = $original_post = get_post($post_id); |
|
362 | 362 | |
363 | - foreach ( $this->entry as $field_id => $value ) { |
|
363 | + foreach ($this->entry as $field_id => $value) { |
|
364 | 364 | |
365 | 365 | //todo: only run through the edit entry configured fields |
366 | 366 | |
367 | - $field = RGFormsModel::get_field( $form, $field_id ); |
|
367 | + $field = RGFormsModel::get_field($form, $field_id); |
|
368 | 368 | |
369 | - if( class_exists('GF_Fields') ) { |
|
370 | - $field = GF_Fields::create( $field ); |
|
369 | + if (class_exists('GF_Fields')) { |
|
370 | + $field = GF_Fields::create($field); |
|
371 | 371 | } |
372 | 372 | |
373 | - if( GFCommon::is_post_field( $field ) ) { |
|
373 | + if (GFCommon::is_post_field($field)) { |
|
374 | 374 | |
375 | 375 | // Get the value of the field, including $_POSTed value |
376 | - $value = RGFormsModel::get_field_value( $field ); |
|
376 | + $value = RGFormsModel::get_field_value($field); |
|
377 | 377 | |
378 | 378 | // Convert the field object in 1.9 to an array for backward compatibility |
379 | - $field_array = GVCommon::get_field_array( $field ); |
|
379 | + $field_array = GVCommon::get_field_array($field); |
|
380 | 380 | |
381 | - switch( $field_array['type'] ) { |
|
381 | + switch ($field_array['type']) { |
|
382 | 382 | |
383 | 383 | case 'post_title': |
384 | 384 | case 'post_content': |
@@ -386,38 +386,38 @@ discard block |
||
386 | 386 | $updated_post->{$field_array['type']} = $value; |
387 | 387 | break; |
388 | 388 | case 'post_tags': |
389 | - wp_set_post_tags( $post_id, $value, false ); |
|
389 | + wp_set_post_tags($post_id, $value, false); |
|
390 | 390 | break; |
391 | 391 | case 'post_category': |
392 | 392 | |
393 | - $categories = is_array( $value ) ? array_values( $value ) : (array)$value; |
|
394 | - $categories = array_filter( $categories ); |
|
393 | + $categories = is_array($value) ? array_values($value) : (array)$value; |
|
394 | + $categories = array_filter($categories); |
|
395 | 395 | |
396 | - wp_set_post_categories( $post_id, $categories, false ); |
|
396 | + wp_set_post_categories($post_id, $categories, false); |
|
397 | 397 | |
398 | 398 | // prepare value to be saved in the entry |
399 | - $field = GFCommon::add_categories_as_choices( $field, '' ); |
|
399 | + $field = GFCommon::add_categories_as_choices($field, ''); |
|
400 | 400 | |
401 | 401 | // if post_category is type checkbox, then value is an array of inputs |
402 | - if( isset( $value[ strval( $field_id ) ] ) ) { |
|
403 | - foreach( $value as $input_id => $val ) { |
|
404 | - $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
|
405 | - $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); |
|
402 | + if (isset($value[strval($field_id)])) { |
|
403 | + foreach ($value as $input_id => $val) { |
|
404 | + $input_name = 'input_'.str_replace('.', '_', $input_id); |
|
405 | + $this->entry[strval($input_id)] = RGFormsModel::prepare_value($form, $field, $val, $input_name, $this->entry['id']); |
|
406 | 406 | } |
407 | 407 | } else { |
408 | - $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
|
409 | - $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); |
|
408 | + $input_name = 'input_'.str_replace('.', '_', $field_id); |
|
409 | + $this->entry[strval($field_id)] = RGFormsModel::prepare_value($form, $field, $value, $input_name, $this->entry['id']); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | break; |
413 | 413 | case 'post_custom_field': |
414 | 414 | |
415 | - $input_type = RGFormsModel::get_input_type( $field ); |
|
415 | + $input_type = RGFormsModel::get_input_type($field); |
|
416 | 416 | $custom_field_name = $field_array['postCustomFieldName']; |
417 | 417 | |
418 | 418 | // Only certain custom field types are supported |
419 | - if( !in_array( $input_type, array( 'list', 'fileupload' ) ) ) { |
|
420 | - update_post_meta( $post_id, $custom_field_name, $value ); |
|
419 | + if (!in_array($input_type, array('list', 'fileupload'))) { |
|
420 | + update_post_meta($post_id, $custom_field_name, $value); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | break; |
@@ -430,13 +430,13 @@ discard block |
||
430 | 430 | } |
431 | 431 | |
432 | 432 | //ignore fields that have not changed |
433 | - if ( $value === rgget( (string) $field_id, $this->entry ) ) { |
|
433 | + if ($value === rgget((string)$field_id, $this->entry)) { |
|
434 | 434 | continue; |
435 | 435 | } |
436 | 436 | |
437 | 437 | // update entry |
438 | - if( 'post_category' !== $field->type ) { |
|
439 | - $this->entry[ strval( $field_id ) ] = $value; |
|
438 | + if ('post_category' !== $field->type) { |
|
439 | + $this->entry[strval($field_id)] = $value; |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | $update_entry = true; |
@@ -445,24 +445,24 @@ discard block |
||
445 | 445 | |
446 | 446 | } |
447 | 447 | |
448 | - if( $update_entry ) { |
|
448 | + if ($update_entry) { |
|
449 | 449 | |
450 | - $return_entry = GFAPI::update_entry( $this->entry ); |
|
450 | + $return_entry = GFAPI::update_entry($this->entry); |
|
451 | 451 | |
452 | - if( is_wp_error( $return_entry ) ) { |
|
453 | - do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
|
452 | + if (is_wp_error($return_entry)) { |
|
453 | + do_action('gravityview_log_error', 'Updating the entry post fields failed', $return_entry); |
|
454 | 454 | } else { |
455 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
455 | + do_action('gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded'); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | } |
459 | 459 | |
460 | - $return_post = wp_update_post( $updated_post, true ); |
|
460 | + $return_post = wp_update_post($updated_post, true); |
|
461 | 461 | |
462 | - if( is_wp_error( $return_post ) ) { |
|
463 | - do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
|
462 | + if (is_wp_error($return_post)) { |
|
463 | + do_action('gravityview_log_error', 'Updating the post content failed', $return_post); |
|
464 | 464 | } else { |
465 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded' ); |
|
465 | + do_action('gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded'); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | } |
@@ -478,18 +478,18 @@ discard block |
||
478 | 478 | */ |
479 | 479 | function after_update() { |
480 | 480 | |
481 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
482 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
481 | + do_action('gform_after_update_entry', $this->form, $this->entry['id']); |
|
482 | + do_action("gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id']); |
|
483 | 483 | |
484 | 484 | // Re-define the entry now that we've updated it. |
485 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
485 | + $entry = RGFormsModel::get_lead($this->entry['id']); |
|
486 | 486 | |
487 | - $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
487 | + $entry = GFFormsModel::set_entry_meta($entry, $this->form); |
|
488 | 488 | |
489 | 489 | // We need to clear the cache because Gravity Forms caches the field values, which |
490 | 490 | // we have just updated. |
491 | 491 | foreach ($this->form['fields'] as $key => $field) { |
492 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
492 | + GFFormsModel::refresh_lead_field_value($entry['id'], $field->id); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | $this->entry = $entry; |
@@ -503,19 +503,19 @@ discard block |
||
503 | 503 | */ |
504 | 504 | public function edit_entry_form() { |
505 | 505 | |
506 | - $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
506 | + $back_link = esc_url(remove_query_arg(array('page', 'view', 'edit'))); |
|
507 | 507 | |
508 | 508 | ?> |
509 | 509 | |
510 | 510 | <div class="gv-edit-entry-wrapper"><?php |
511 | 511 | |
512 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
512 | + $javascript = gravityview_ob_include(GravityView_Edit_Entry::$file.'/partials/inline-javascript.php', $this); |
|
513 | 513 | |
514 | 514 | /** |
515 | 515 | * Fixes weird wpautop() issue |
516 | 516 | * @see https://github.com/katzwebservices/GravityView/issues/451 |
517 | 517 | */ |
518 | - echo gravityview_strip_whitespace( $javascript ); |
|
518 | + echo gravityview_strip_whitespace($javascript); |
|
519 | 519 | |
520 | 520 | ?><h2 class="gv-edit-entry-title"> |
521 | 521 | <span><?php |
@@ -525,27 +525,27 @@ discard block |
||
525 | 525 | * @param string $edit_entry_title Modify the "Edit Entry" title |
526 | 526 | * @param GravityView_Edit_Entry_Render $this This object |
527 | 527 | */ |
528 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
528 | + $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this); |
|
529 | 529 | |
530 | - echo esc_attr( $edit_entry_title ); |
|
530 | + echo esc_attr($edit_entry_title); |
|
531 | 531 | ?></span> |
532 | 532 | </h2> |
533 | 533 | |
534 | 534 | <?php |
535 | 535 | |
536 | 536 | // Display the success message |
537 | - if( rgpost('action') === 'update' ) { |
|
537 | + if (rgpost('action') === 'update') { |
|
538 | 538 | |
539 | - if( ! $this->is_valid ){ |
|
539 | + if (!$this->is_valid) { |
|
540 | 540 | |
541 | 541 | // Keeping this compatible with Gravity Forms. |
542 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
542 | + $validation_message = "<div class='validation_error'>".__('There was a problem with your submission.', 'gravityview')." ".__('Errors have been highlighted below.', 'gravityview')."</div>"; |
|
543 | 543 | $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
544 | 544 | |
545 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
545 | + echo GVCommon::generate_notice($message, 'gv-error'); |
|
546 | 546 | |
547 | 547 | } else { |
548 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
548 | + $entry_updated_message = sprintf(esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'.$back_link.'">', '</a>'); |
|
549 | 549 | |
550 | 550 | /** |
551 | 551 | * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
@@ -555,9 +555,9 @@ discard block |
||
555 | 555 | * @param array $entry Gravity Forms entry array |
556 | 556 | * @param string $back_link URL to return to the original entry. @since 1.6 |
557 | 557 | */ |
558 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
558 | + $message = apply_filters('gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry, $back_link); |
|
559 | 559 | |
560 | - echo GVCommon::generate_notice( $message ); |
|
560 | + echo GVCommon::generate_notice($message); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | } |
@@ -570,9 +570,9 @@ discard block |
||
570 | 570 | |
571 | 571 | <?php |
572 | 572 | |
573 | - wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
573 | + wp_nonce_field(self::$nonce_key, self::$nonce_key); |
|
574 | 574 | |
575 | - wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
575 | + wp_nonce_field(self::$nonce_field, self::$nonce_field, false); |
|
576 | 576 | |
577 | 577 | // Most of this is needed for GFFormDisplay::validate(), but `gform_unique_id` is needed for file cleanup. |
578 | 578 | |
@@ -612,13 +612,13 @@ discard block |
||
612 | 612 | */ |
613 | 613 | private function render_edit_form() { |
614 | 614 | |
615 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
616 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
617 | - add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
618 | - add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
615 | + add_filter('gform_pre_render', array($this, 'filter_modify_form_fields'), 5000, 3); |
|
616 | + add_filter('gform_submit_button', array($this, 'render_form_buttons')); |
|
617 | + add_filter('gform_disable_view_counter', '__return_true'); |
|
618 | + add_filter('gform_field_input', array($this, 'modify_edit_field_input'), 10, 5); |
|
619 | 619 | |
620 | 620 | // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
621 | - unset( $_GET['page'] ); |
|
621 | + unset($_GET['page']); |
|
622 | 622 | |
623 | 623 | // TODO: Make sure validation isn't handled by GF |
624 | 624 | // TODO: Include CSS for file upload fields |
@@ -626,12 +626,12 @@ discard block |
||
626 | 626 | // TODO: Product fields are not editable |
627 | 627 | // TODO: Check Updated and Error messages |
628 | 628 | |
629 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
629 | + $html = GFFormDisplay::get_form($this->form['id'], false, false, true, $this->entry); |
|
630 | 630 | |
631 | - remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
632 | - remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
633 | - remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
634 | - remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
631 | + remove_filter('gform_pre_render', array($this, 'filter_modify_form_fields'), 5000); |
|
632 | + remove_filter('gform_submit_button', array($this, 'render_form_buttons')); |
|
633 | + remove_filter('gform_disable_view_counter', '__return_true'); |
|
634 | + remove_filter('gform_field_input', array($this, 'modify_edit_field_input'), 10); |
|
635 | 635 | |
636 | 636 | echo $html; |
637 | 637 | } |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | * @return string |
643 | 643 | */ |
644 | 644 | public function render_form_buttons() { |
645 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
645 | + return gravityview_ob_include(GravityView_Edit_Entry::$file.'/partials/form-buttons.php', $this); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | |
@@ -659,20 +659,20 @@ discard block |
||
659 | 659 | * |
660 | 660 | * @return array Modified form array |
661 | 661 | */ |
662 | - public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
662 | + public function filter_modify_form_fields($form, $ajax = false, $field_values = '') { |
|
663 | 663 | |
664 | 664 | // In case we have validated the form, use it to inject the validation results into the form render |
665 | - if( isset( $this->form_after_validation ) ) { |
|
665 | + if (isset($this->form_after_validation)) { |
|
666 | 666 | $form = $this->form_after_validation; |
667 | 667 | } else { |
668 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
668 | + $form['fields'] = $this->get_configured_edit_fields($form, $this->view_id); |
|
669 | 669 | } |
670 | 670 | |
671 | - $form = $this->filter_conditional_logic( $form ); |
|
671 | + $form = $this->filter_conditional_logic($form); |
|
672 | 672 | |
673 | 673 | // for now we don't support Save and Continue feature. |
674 | - if( ! self::$supports_save_and_continue ) { |
|
675 | - unset( $form['save'] ); |
|
674 | + if (!self::$supports_save_and_continue) { |
|
675 | + unset($form['save']); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | return $form; |
@@ -691,19 +691,19 @@ discard block |
||
691 | 691 | * |
692 | 692 | * @return mixed |
693 | 693 | */ |
694 | - function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
694 | + function modify_edit_field_input($field_content = '', $field, $value, $lead_id = 0, $form_id) { |
|
695 | 695 | |
696 | 696 | // If the form has been submitted, then we don't need to pre-fill the values, |
697 | 697 | // Except for fileupload type - run always!! |
698 | - if( |
|
698 | + if ( |
|
699 | 699 | $this->is_edit_entry_submission() && 'fileupload' !== $field->type |
700 | - || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
700 | + || GFCommon::is_product_field($field->type) // Prevent product fields from appearing editable |
|
701 | 701 | ) { |
702 | 702 | return $field_content; |
703 | 703 | } |
704 | 704 | |
705 | 705 | // Turn on Admin-style display for file upload fields only |
706 | - if( 'fileupload' === $field->type ) { |
|
706 | + if ('fileupload' === $field->type) { |
|
707 | 707 | $_GET['page'] = 'gf_entries'; |
708 | 708 | } |
709 | 709 | |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
712 | 712 | |
713 | 713 | // add categories as choices for Post Category field |
714 | - if ( 'post_category' === $field->type ) { |
|
715 | - $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
714 | + if ('post_category' === $field->type) { |
|
715 | + $field = GFCommon::add_categories_as_choices($field, $value); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
@@ -721,55 +721,55 @@ discard block |
||
721 | 721 | * @param $field GF_Field object Gravity Forms field object |
722 | 722 | * @since 1.13 |
723 | 723 | */ |
724 | - $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
724 | + $override_saved_value = apply_filters('gravityview/edit_entry/pre_populate/override', false, $field); |
|
725 | 725 | |
726 | 726 | // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
727 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
727 | + if (isset($field->inputs) && is_array($field->inputs) && !in_array($field->type, array('time', 'date'))) { |
|
728 | 728 | |
729 | 729 | $field_value = array(); |
730 | 730 | |
731 | 731 | // only accept pre-populated values if the field doesn't have any choice selected. |
732 | 732 | $allow_pre_populated = $field->allowsPrepopulate; |
733 | 733 | |
734 | - foreach ( (array)$field->inputs as $input ) { |
|
734 | + foreach ((array)$field->inputs as $input) { |
|
735 | 735 | |
736 | - $input_id = strval( $input['id'] ); |
|
736 | + $input_id = strval($input['id']); |
|
737 | 737 | |
738 | - if ( ! empty( $this->entry[ $input_id ] ) ) { |
|
739 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
738 | + if (!empty($this->entry[$input_id])) { |
|
739 | + $field_value[$input_id] = 'post_category' === $field->type ? GFCommon::format_post_category($this->entry[$input_id], true) : $this->entry[$input_id]; |
|
740 | 740 | $allow_pre_populated = false; |
741 | 741 | } |
742 | 742 | |
743 | 743 | } |
744 | 744 | |
745 | - $pre_value = $field->get_value_submission( array(), false ); |
|
745 | + $pre_value = $field->get_value_submission(array(), false); |
|
746 | 746 | |
747 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !empty( $pre_value ) ) ? $field_value : $pre_value; |
|
747 | + $field_value = !$allow_pre_populated && !($override_saved_value && !empty($pre_value)) ? $field_value : $pre_value; |
|
748 | 748 | |
749 | 749 | } else { |
750 | 750 | |
751 | - $id = intval( $field->id ); |
|
751 | + $id = intval($field->id); |
|
752 | 752 | |
753 | 753 | // get pre-populated value if exists |
754 | - $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
754 | + $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value($field->inputName, array(), $field) : ''; |
|
755 | 755 | |
756 | 756 | // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
757 | 757 | // or pre-populated value if not empty and set to override saved value |
758 | - $field_value = !empty( $this->entry[ $id ] ) && ! ( $override_saved_value && !empty( $pre_value ) ) ? $this->entry[ $id ] : $pre_value; |
|
758 | + $field_value = !empty($this->entry[$id]) && !($override_saved_value && !empty($pre_value)) ? $this->entry[$id] : $pre_value; |
|
759 | 759 | |
760 | 760 | // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
761 | - if ( 'post_category' === $field->type && !empty( $field_value ) ) { |
|
761 | + if ('post_category' === $field->type && !empty($field_value)) { |
|
762 | 762 | $categories = array(); |
763 | - foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
764 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
763 | + foreach (explode(',', $field_value) as $cat_string) { |
|
764 | + $categories[] = GFCommon::format_post_category($cat_string, true); |
|
765 | 765 | } |
766 | - $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
766 | + $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode('', $categories); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | } |
770 | 770 | |
771 | 771 | // if value is empty get the default value if defined |
772 | - $field_value = $field->get_value_default_if_empty( $field_value ); |
|
772 | + $field_value = $field->get_value_default_if_empty($field_value); |
|
773 | 773 | |
774 | 774 | /** |
775 | 775 | * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
@@ -777,18 +777,18 @@ discard block |
||
777 | 777 | * @param mixed $field_value field value used to populate the input |
778 | 778 | * @param object $field Gravity Forms field object ( Class GF_Field ) |
779 | 779 | */ |
780 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
780 | + $field_value = apply_filters('gravityview/edit_entry/field_value', $field_value, $field); |
|
781 | 781 | |
782 | 782 | // Prevent any PHP warnings, like undefined index |
783 | 783 | ob_start(); |
784 | 784 | |
785 | - $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
785 | + $return = $field->get_field_input($this->form, $field_value, $this->entry); |
|
786 | 786 | |
787 | 787 | // If there was output, it's an error |
788 | 788 | $warnings = ob_get_clean(); |
789 | 789 | |
790 | - if( !empty( $warnings ) ) { |
|
791 | - do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
790 | + if (!empty($warnings)) { |
|
791 | + do_action('gravityview_log_error', __METHOD__.$warnings, $field_value); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | * We need the fileupload html field to render with the proper id |
797 | 797 | * ( <li id="field_80_16" ... > ) |
798 | 798 | */ |
799 | - unset( $_GET['page'] ); |
|
799 | + unset($_GET['page']); |
|
800 | 800 | |
801 | 801 | return $return; |
802 | 802 | } |
@@ -812,14 +812,14 @@ discard block |
||
812 | 812 | * @param array $field Gravity Forms field array |
813 | 813 | * @return string [description] |
814 | 814 | */ |
815 | - public function get_field_value( $value, $lead, $field ) { |
|
815 | + public function get_field_value($value, $lead, $field) { |
|
816 | 816 | |
817 | 817 | // The form's not being edited; use the original value |
818 | - if( ! $this->is_edit_entry_submission() ) { |
|
818 | + if (!$this->is_edit_entry_submission()) { |
|
819 | 819 | return $value; |
820 | 820 | } |
821 | 821 | |
822 | - return GFFormsModel::get_field_value( $field, $lead, true ); |
|
822 | + return GFFormsModel::get_field_value($field, $lead, true); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | |
@@ -834,19 +834,19 @@ discard block |
||
834 | 834 | * @param array $form GF Form |
835 | 835 | * @return array Modified GF Form |
836 | 836 | */ |
837 | - function gform_pre_validation( $form ) { |
|
837 | + function gform_pre_validation($form) { |
|
838 | 838 | |
839 | - if( ! $this->verify_nonce() ) { |
|
839 | + if (!$this->verify_nonce()) { |
|
840 | 840 | return $form; |
841 | 841 | } |
842 | 842 | |
843 | 843 | // Fix PHP warning regarding undefined index. |
844 | - foreach ( $form['fields'] as &$field) { |
|
844 | + foreach ($form['fields'] as &$field) { |
|
845 | 845 | |
846 | 846 | // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
847 | 847 | // expects certain field array items to be set. |
848 | - foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
849 | - $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
848 | + foreach (array('noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions') as $key) { |
|
849 | + $field->{$key} = isset($field->{$key} ) ? $field->{$key} : NULL; |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | // unset emailConfirmEnabled for email type fields |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | $field['emailConfirmEnabled'] = ''; |
855 | 855 | }*/ |
856 | 856 | |
857 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
857 | + switch (RGFormsModel::get_input_type($field)) { |
|
858 | 858 | |
859 | 859 | /** |
860 | 860 | * 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. |
@@ -875,49 +875,49 @@ discard block |
||
875 | 875 | $value = NULL; |
876 | 876 | |
877 | 877 | // Use the previous entry value as the default. |
878 | - if( isset( $entry[ $field->id ] ) ) { |
|
879 | - $value = $entry[ $field->id ]; |
|
878 | + if (isset($entry[$field->id])) { |
|
879 | + $value = $entry[$field->id]; |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | // If this is a single upload file |
883 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
884 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
883 | + if (!empty($_FILES[$input_name]) && !empty($_FILES[$input_name]['name'])) { |
|
884 | + $file_path = GFFormsModel::get_file_upload_path($form['id'], $_FILES[$input_name]['name']); |
|
885 | 885 | $value = $file_path['url']; |
886 | 886 | |
887 | 887 | } else { |
888 | 888 | |
889 | 889 | // Fix PHP warning on line 1498 of form_display.php for post_image fields |
890 | 890 | // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
891 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
891 | + $_FILES[$input_name] = array('name' => '', 'size' => ''); |
|
892 | 892 | |
893 | 893 | } |
894 | 894 | |
895 | - if( rgar($field, "multipleFiles") ) { |
|
895 | + if (rgar($field, "multipleFiles")) { |
|
896 | 896 | |
897 | 897 | // If there are fresh uploads, process and merge them. |
898 | 898 | // Otherwise, use the passed values, which should be json-encoded array of URLs |
899 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
899 | + if (isset(GFFormsModel::$uploaded_files[$form_id][$input_name])) { |
|
900 | 900 | |
901 | - $value = empty( $value ) ? '[]' : $value; |
|
902 | - $value = stripslashes_deep( $value ); |
|
903 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
901 | + $value = empty($value) ? '[]' : $value; |
|
902 | + $value = stripslashes_deep($value); |
|
903 | + $value = GFFormsModel::prepare_value($form, $field, $value, $input_name, $entry['id'], array()); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | } else { |
907 | 907 | |
908 | 908 | // A file already exists when editing an entry |
909 | 909 | // We set this to solve issue when file upload fields are required. |
910 | - GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
910 | + GFFormsModel::$uploaded_files[$form_id][$input_name] = $value; |
|
911 | 911 | |
912 | 912 | } |
913 | 913 | |
914 | - $_POST[ $input_name ] = $value; |
|
914 | + $_POST[$input_name] = $value; |
|
915 | 915 | |
916 | 916 | break; |
917 | 917 | case 'number': |
918 | 918 | // Fix "undefined index" issue at line 1286 in form_display.php |
919 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
920 | - $_POST['input_'.$field->id ] = NULL; |
|
919 | + if (!isset($_POST['input_'.$field->id])) { |
|
920 | + $_POST['input_'.$field->id] = NULL; |
|
921 | 921 | } |
922 | 922 | break; |
923 | 923 | case 'captcha': |
@@ -943,8 +943,8 @@ discard block |
||
943 | 943 | function validate() { |
944 | 944 | |
945 | 945 | // If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
946 | - if ( class_exists( 'GFUser' ) ) { |
|
947 | - remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
946 | + if (class_exists('GFUser')) { |
|
947 | + remove_filter('gform_validation', array('GFUser', 'user_registration_validation')); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
@@ -952,22 +952,22 @@ discard block |
||
952 | 952 | * You can enter whatever you want! |
953 | 953 | * We try validating, and customize the results using `self::custom_validation()` |
954 | 954 | */ |
955 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
955 | + add_filter('gform_validation_'.$this->form_id, array($this, 'custom_validation'), 10, 4); |
|
956 | 956 | |
957 | 957 | // Needed by the validate funtion |
958 | 958 | $failed_validation_page = NULL; |
959 | - $field_values = RGForms::post( 'gform_field_values' ); |
|
959 | + $field_values = RGForms::post('gform_field_values'); |
|
960 | 960 | |
961 | 961 | // Prevent entry limit from running when editing an entry, also |
962 | 962 | // prevent form scheduling from preventing editing |
963 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
963 | + unset($this->form['limitEntries'], $this->form['scheduleForm']); |
|
964 | 964 | |
965 | 965 | // Hide fields depending on Edit Entry settings |
966 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
966 | + $this->form['fields'] = $this->get_configured_edit_fields($this->form, $this->view_id); |
|
967 | 967 | |
968 | - $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
968 | + $this->is_valid = GFFormDisplay::validate($this->form, $field_values, 1, $failed_validation_page); |
|
969 | 969 | |
970 | - remove_filter( 'gform_validation_'.$this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
970 | + remove_filter('gform_validation_'.$this->form_id, array($this, 'custom_validation'), 10); |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | |
@@ -982,55 +982,55 @@ discard block |
||
982 | 982 | * @param [type] $validation_results [description] |
983 | 983 | * @return [type] [description] |
984 | 984 | */ |
985 | - function custom_validation( $validation_results ) { |
|
985 | + function custom_validation($validation_results) { |
|
986 | 986 | |
987 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
987 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results); |
|
988 | 988 | |
989 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
989 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html(print_r($_POST, true))); |
|
990 | 990 | |
991 | 991 | $gv_valid = true; |
992 | 992 | |
993 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
993 | + foreach ($validation_results['form']['fields'] as $key => &$field) { |
|
994 | 994 | |
995 | - $value = RGFormsModel::get_field_value( $field ); |
|
996 | - $field_type = RGFormsModel::get_input_type( $field ); |
|
995 | + $value = RGFormsModel::get_field_value($field); |
|
996 | + $field_type = RGFormsModel::get_input_type($field); |
|
997 | 997 | |
998 | 998 | // Validate always |
999 | - switch ( $field_type ) { |
|
999 | + switch ($field_type) { |
|
1000 | 1000 | |
1001 | 1001 | |
1002 | 1002 | case 'fileupload' : |
1003 | 1003 | |
1004 | 1004 | // in case nothing is uploaded but there are already files saved |
1005 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
1005 | + if (!empty($field->failed_validation) && !empty($field->isRequired) && !empty($value)) { |
|
1006 | 1006 | $field->failed_validation = false; |
1007 | - unset( $field->validation_message ); |
|
1007 | + unset($field->validation_message); |
|
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | // validate if multi file upload reached max number of files [maxFiles] => 2 |
1011 | - if( rgar( $field, 'maxFiles') && rgar( $field, 'multipleFiles') ) { |
|
1011 | + if (rgar($field, 'maxFiles') && rgar($field, 'multipleFiles')) { |
|
1012 | 1012 | |
1013 | - $input_name = 'input_' . $field->id; |
|
1013 | + $input_name = 'input_'.$field->id; |
|
1014 | 1014 | //uploaded |
1015 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
1015 | + $file_names = isset(GFFormsModel::$uploaded_files[$validation_results['form']['id']][$input_name]) ? GFFormsModel::$uploaded_files[$validation_results['form']['id']][$input_name] : array(); |
|
1016 | 1016 | |
1017 | 1017 | //existent |
1018 | 1018 | $entry = $this->get_entry(); |
1019 | 1019 | $value = NULL; |
1020 | - if( isset( $entry[ $field->id ] ) ) { |
|
1021 | - $value = json_decode( $entry[ $field->id ], true ); |
|
1020 | + if (isset($entry[$field->id])) { |
|
1021 | + $value = json_decode($entry[$field->id], true); |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | // count uploaded files and existent entry files |
1025 | - $count_files = count( $file_names ) + count( $value ); |
|
1025 | + $count_files = count($file_names) + count($value); |
|
1026 | 1026 | |
1027 | - if( $count_files > $field->maxFiles ) { |
|
1028 | - $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
1027 | + if ($count_files > $field->maxFiles) { |
|
1028 | + $field->validation_message = __('Maximum number of files reached', 'gravityview'); |
|
1029 | 1029 | $field->failed_validation = 1; |
1030 | 1030 | $gv_valid = false; |
1031 | 1031 | |
1032 | 1032 | // in case of error make sure the newest upload files are removed from the upload input |
1033 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
1033 | + GFFormsModel::$uploaded_files[$validation_results['form']['id']] = null; |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | } |
@@ -1041,11 +1041,11 @@ discard block |
||
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | // This field has failed validation. |
1044 | - if( !empty( $field->failed_validation ) ) { |
|
1044 | + if (!empty($field->failed_validation)) { |
|
1045 | 1045 | |
1046 | - do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
1046 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array('field' => $field, 'value' => $value)); |
|
1047 | 1047 | |
1048 | - switch ( $field_type ) { |
|
1048 | + switch ($field_type) { |
|
1049 | 1049 | |
1050 | 1050 | // Captchas don't need to be re-entered. |
1051 | 1051 | case 'captcha': |
@@ -1053,39 +1053,39 @@ discard block |
||
1053 | 1053 | // Post Image fields aren't editable, so we un-fail them. |
1054 | 1054 | case 'post_image': |
1055 | 1055 | $field->failed_validation = false; |
1056 | - unset( $field->validation_message ); |
|
1056 | + unset($field->validation_message); |
|
1057 | 1057 | break; |
1058 | 1058 | |
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | // You can't continue inside a switch, so we do it after. |
1062 | - if( empty( $field->failed_validation ) ) { |
|
1062 | + if (empty($field->failed_validation)) { |
|
1063 | 1063 | continue; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | // checks if the No Duplicates option is not validating entry against itself, since |
1067 | 1067 | // we're editing a stored entry, it would also assume it's a duplicate. |
1068 | - if( !empty( $field->noDuplicates ) ) { |
|
1068 | + if (!empty($field->noDuplicates)) { |
|
1069 | 1069 | |
1070 | 1070 | $entry = $this->get_entry(); |
1071 | 1071 | |
1072 | 1072 | // If the value of the entry is the same as the stored value |
1073 | 1073 | // Then we can assume it's not a duplicate, it's the same. |
1074 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
1074 | + if (!empty($entry) && $value == $entry[$field->id]) { |
|
1075 | 1075 | //if value submitted was not changed, then don't validate |
1076 | 1076 | $field->failed_validation = false; |
1077 | 1077 | |
1078 | - unset( $field->validation_message ); |
|
1078 | + unset($field->validation_message); |
|
1079 | 1079 | |
1080 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
1080 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry); |
|
1081 | 1081 | |
1082 | 1082 | continue; |
1083 | 1083 | } |
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | // if here then probably we are facing the validation 'At least one field must be filled out' |
1087 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
1088 | - unset( $field->validation_message ); |
|
1087 | + if (GFFormDisplay::is_empty($field, $this->form_id) && empty($field->isRequired)) { |
|
1088 | + unset($field->validation_message); |
|
1089 | 1089 | $field->validation_message = false; |
1090 | 1090 | continue; |
1091 | 1091 | } |
@@ -1098,7 +1098,7 @@ discard block |
||
1098 | 1098 | |
1099 | 1099 | $validation_results['is_valid'] = $gv_valid; |
1100 | 1100 | |
1101 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
1101 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results); |
|
1102 | 1102 | |
1103 | 1103 | // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
1104 | 1104 | $this->form_after_validation = $validation_results['form']; |
@@ -1114,9 +1114,9 @@ discard block |
||
1114 | 1114 | */ |
1115 | 1115 | private function get_entry() { |
1116 | 1116 | |
1117 | - if( empty( $this->entry ) ) { |
|
1117 | + if (empty($this->entry)) { |
|
1118 | 1118 | // Get the database value of the entry that's being edited |
1119 | - $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
1119 | + $this->entry = gravityview_get_entry(GravityView_frontend::is_single_entry()); |
|
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | return $this->entry; |
@@ -1135,22 +1135,22 @@ discard block |
||
1135 | 1135 | * |
1136 | 1136 | * @return array Array of fields that are configured in the Edit tab in the Admin |
1137 | 1137 | */ |
1138 | - private function get_configured_edit_fields( $form, $view_id ) { |
|
1138 | + private function get_configured_edit_fields($form, $view_id) { |
|
1139 | 1139 | |
1140 | 1140 | // Get all fields for form |
1141 | - $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
1141 | + $properties = GravityView_View_Data::getInstance()->get_fields($view_id); |
|
1142 | 1142 | |
1143 | 1143 | // If edit tab not yet configured, show all fields |
1144 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
1144 | + $edit_fields = !empty($properties['edit_edit-fields']) ? $properties['edit_edit-fields'] : NULL; |
|
1145 | 1145 | |
1146 | 1146 | // Show hidden fields as text fields |
1147 | - $form = $this->fix_hidden_fields( $form ); |
|
1147 | + $form = $this->fix_hidden_fields($form); |
|
1148 | 1148 | |
1149 | 1149 | // Hide fields depending on admin settings |
1150 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
1150 | + $fields = $this->filter_fields($form['fields'], $edit_fields); |
|
1151 | 1151 | |
1152 | 1152 | // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
1153 | - $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
1153 | + $fields = $this->filter_admin_only_fields($fields, $edit_fields, $form, $view_id); |
|
1154 | 1154 | |
1155 | 1155 | return $fields; |
1156 | 1156 | } |
@@ -1162,14 +1162,14 @@ discard block |
||
1162 | 1162 | * |
1163 | 1163 | * @return mixed |
1164 | 1164 | */ |
1165 | - private function fix_hidden_fields( $form ) { |
|
1165 | + private function fix_hidden_fields($form) { |
|
1166 | 1166 | |
1167 | 1167 | /** @var GF_Field $field */ |
1168 | - foreach( $form['fields'] as $key => $field ) { |
|
1169 | - if( 'hidden' === $field->type ) { |
|
1170 | - $text_field = new GF_Field_Text( $field ); |
|
1168 | + foreach ($form['fields'] as $key => $field) { |
|
1169 | + if ('hidden' === $field->type) { |
|
1170 | + $text_field = new GF_Field_Text($field); |
|
1171 | 1171 | $text_field->type = 'text'; |
1172 | - $form['fields'][ $key ] = $text_field; |
|
1172 | + $form['fields'][$key] = $text_field; |
|
1173 | 1173 | } |
1174 | 1174 | } |
1175 | 1175 | |
@@ -1187,9 +1187,9 @@ discard block |
||
1187 | 1187 | * @since 1.5 |
1188 | 1188 | * @return array $fields |
1189 | 1189 | */ |
1190 | - private function filter_fields( $fields, $configured_fields ) { |
|
1190 | + private function filter_fields($fields, $configured_fields) { |
|
1191 | 1191 | |
1192 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
1192 | + if (empty($fields) || !is_array($fields)) { |
|
1193 | 1193 | return $fields; |
1194 | 1194 | } |
1195 | 1195 | |
@@ -1204,9 +1204,9 @@ discard block |
||
1204 | 1204 | * @since 1.9.1 |
1205 | 1205 | * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
1206 | 1206 | */ |
1207 | - $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
1207 | + $hide_product_fields = apply_filters('gravityview/edit_entry/hide-product-fields', empty(self::$supports_product_fields)); |
|
1208 | 1208 | |
1209 | - if( $hide_product_fields ) { |
|
1209 | + if ($hide_product_fields) { |
|
1210 | 1210 | $field_type_blacklist[] = 'option'; |
1211 | 1211 | $field_type_blacklist[] = 'quantity'; |
1212 | 1212 | $field_type_blacklist[] = 'product'; |
@@ -1216,25 +1216,25 @@ discard block |
||
1216 | 1216 | } |
1217 | 1217 | |
1218 | 1218 | // First, remove blacklist |
1219 | - foreach ( $fields as $key => $field ) { |
|
1220 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
1221 | - unset( $fields[ $key ] ); |
|
1219 | + foreach ($fields as $key => $field) { |
|
1220 | + if (in_array($field->type, $field_type_blacklist)) { |
|
1221 | + unset($fields[$key]); |
|
1222 | 1222 | } |
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | // The Edit tab has not been configured, so we return all fields by default. |
1226 | - if( empty( $configured_fields ) ) { |
|
1226 | + if (empty($configured_fields)) { |
|
1227 | 1227 | return $fields; |
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | // The edit tab has been configured, so we loop through to configured settings |
1231 | - foreach ( $configured_fields as $configured_field ) { |
|
1231 | + foreach ($configured_fields as $configured_field) { |
|
1232 | 1232 | |
1233 | 1233 | /** @var GF_Field $field */ |
1234 | - foreach ( $fields as $field ) { |
|
1234 | + foreach ($fields as $field) { |
|
1235 | 1235 | |
1236 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
1237 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
1236 | + if (intval($configured_field['id']) === intval($field->id) && $this->user_can_edit_field($configured_field, false)) { |
|
1237 | + $edit_fields[] = $this->merge_field_properties($field, $configured_field); |
|
1238 | 1238 | break; |
1239 | 1239 | } |
1240 | 1240 | |
@@ -1253,18 +1253,18 @@ discard block |
||
1253 | 1253 | * @since 1.5 |
1254 | 1254 | * @return array |
1255 | 1255 | */ |
1256 | - private function merge_field_properties( $field, $field_setting ) { |
|
1256 | + private function merge_field_properties($field, $field_setting) { |
|
1257 | 1257 | |
1258 | 1258 | $return_field = $field; |
1259 | 1259 | |
1260 | - if( empty( $field_setting['show_label'] ) ) { |
|
1260 | + if (empty($field_setting['show_label'])) { |
|
1261 | 1261 | $return_field->label = ''; |
1262 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
1262 | + } elseif (!empty($field_setting['custom_label'])) { |
|
1263 | 1263 | $return_field->label = $field_setting['custom_label']; |
1264 | 1264 | } |
1265 | 1265 | |
1266 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
1267 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
1266 | + if (!empty($field_setting['custom_class'])) { |
|
1267 | + $return_field->cssClass .= ' '.gravityview_sanitize_html_class($field_setting['custom_class']); |
|
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | /** |
@@ -1289,7 +1289,7 @@ discard block |
||
1289 | 1289 | * |
1290 | 1290 | * @return array Possibly modified form array |
1291 | 1291 | */ |
1292 | - function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
1292 | + function filter_admin_only_fields($fields = array(), $edit_fields = null, $form = array(), $view_id = 0) { |
|
1293 | 1293 | |
1294 | 1294 | /** |
1295 | 1295 | * @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 |
@@ -1300,13 +1300,13 @@ discard block |
||
1300 | 1300 | * @param array $form GF Form array |
1301 | 1301 | * @param int $view_id View ID |
1302 | 1302 | */ |
1303 | - $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
1303 | + $use_gf_adminonly_setting = apply_filters('gravityview/edit_entry/use_gf_admin_only_setting', empty($edit_fields), $form, $view_id); |
|
1304 | 1304 | |
1305 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
1305 | + if ($use_gf_adminonly_setting && false === GVCommon::has_cap('gravityforms_edit_entries', $this->entry['id'])) { |
|
1306 | 1306 | return $fields; |
1307 | 1307 | } |
1308 | 1308 | |
1309 | - foreach( $fields as &$field ) { |
|
1309 | + foreach ($fields as &$field) { |
|
1310 | 1310 | $field->adminOnly = false; |
1311 | 1311 | } |
1312 | 1312 | |
@@ -1323,7 +1323,7 @@ discard block |
||
1323 | 1323 | * @param array $form Gravity Forms form |
1324 | 1324 | * @return array Modified form, if not using Conditional Logic |
1325 | 1325 | */ |
1326 | - function filter_conditional_logic( $form ) { |
|
1326 | + function filter_conditional_logic($form) { |
|
1327 | 1327 | |
1328 | 1328 | /** |
1329 | 1329 | * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
@@ -1331,18 +1331,18 @@ discard block |
||
1331 | 1331 | * @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 |
1332 | 1332 | * @param array $form Gravity Forms form |
1333 | 1333 | */ |
1334 | - $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
1334 | + $use_conditional_logic = apply_filters('gravityview/edit_entry/conditional_logic', true, $form); |
|
1335 | 1335 | |
1336 | - if( $use_conditional_logic ) { |
|
1336 | + if ($use_conditional_logic) { |
|
1337 | 1337 | return $form; |
1338 | 1338 | } |
1339 | 1339 | |
1340 | - foreach( $form['fields'] as &$field ) { |
|
1340 | + foreach ($form['fields'] as &$field) { |
|
1341 | 1341 | /* @var GF_Field $field */ |
1342 | 1342 | $field->conditionalLogic = null; |
1343 | 1343 | } |
1344 | 1344 | |
1345 | - unset( $form['button']['conditionalLogic'] ); |
|
1345 | + unset($form['button']['conditionalLogic']); |
|
1346 | 1346 | |
1347 | 1347 | return $form; |
1348 | 1348 | |
@@ -1357,13 +1357,13 @@ discard block |
||
1357 | 1357 | * @param $form |
1358 | 1358 | * @return mixed|void |
1359 | 1359 | */ |
1360 | - function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
1360 | + function manage_conditional_logic($has_conditional_logic, $form) { |
|
1361 | 1361 | |
1362 | - if( ! $this->is_edit_entry() ) { |
|
1362 | + if (!$this->is_edit_entry()) { |
|
1363 | 1363 | return $has_conditional_logic; |
1364 | 1364 | } |
1365 | 1365 | |
1366 | - return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
1366 | + return apply_filters('gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form); |
|
1367 | 1367 | |
1368 | 1368 | } |
1369 | 1369 | |
@@ -1382,7 +1382,7 @@ discard block |
||
1382 | 1382 | * @param boolean $echo Show error messages in the form? |
1383 | 1383 | * @return boolean True: can edit form. False: nope. |
1384 | 1384 | */ |
1385 | - function user_can_edit_entry( $echo = false ) { |
|
1385 | + function user_can_edit_entry($echo = false) { |
|
1386 | 1386 | |
1387 | 1387 | $error = NULL; |
1388 | 1388 | |
@@ -1391,58 +1391,58 @@ discard block |
||
1391 | 1391 | * 2. There are two entries embedded using oEmbed |
1392 | 1392 | * 3. One of the entries has just been saved |
1393 | 1393 | */ |
1394 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
1394 | + if (!empty($_POST['lid']) && !empty($_GET['entry']) && ($_POST['lid'] !== $_GET['entry'])) { |
|
1395 | 1395 | |
1396 | 1396 | $error = true; |
1397 | 1397 | |
1398 | 1398 | } |
1399 | 1399 | |
1400 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
1400 | + if (!empty($_GET['entry']) && (string)$this->entry['id'] !== $_GET['entry']) { |
|
1401 | 1401 | |
1402 | 1402 | $error = true; |
1403 | 1403 | |
1404 | - } elseif( ! $this->verify_nonce() ) { |
|
1404 | + } elseif (!$this->verify_nonce()) { |
|
1405 | 1405 | |
1406 | 1406 | /** |
1407 | 1407 | * If the Entry is embedded, there may be two entries on the same page. |
1408 | 1408 | * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
1409 | 1409 | */ |
1410 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
1410 | + if (GravityView_oEmbed::getInstance()->get_entry_id()) { |
|
1411 | 1411 | $error = true; |
1412 | 1412 | } else { |
1413 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
1413 | + $error = __('The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
1414 | 1414 | } |
1415 | 1415 | |
1416 | 1416 | } |
1417 | 1417 | |
1418 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
1419 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
1418 | + if (!GravityView_Edit_Entry::check_user_cap_edit_entry($this->entry)) { |
|
1419 | + $error = __('You do not have permission to edit this entry.', 'gravityview'); |
|
1420 | 1420 | } |
1421 | 1421 | |
1422 | - if( $this->entry['status'] === 'trash' ) { |
|
1423 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
1422 | + if ($this->entry['status'] === 'trash') { |
|
1423 | + $error = __('You cannot edit the entry; it is in the trash.', 'gravityview'); |
|
1424 | 1424 | } |
1425 | 1425 | |
1426 | 1426 | // No errors; everything's fine here! |
1427 | - if( empty( $error ) ) { |
|
1427 | + if (empty($error)) { |
|
1428 | 1428 | return true; |
1429 | 1429 | } |
1430 | 1430 | |
1431 | - if( $echo && $error !== true ) { |
|
1431 | + if ($echo && $error !== true) { |
|
1432 | 1432 | |
1433 | - $error = esc_html( $error ); |
|
1433 | + $error = esc_html($error); |
|
1434 | 1434 | |
1435 | 1435 | /** |
1436 | 1436 | * @since 1.9 |
1437 | 1437 | */ |
1438 | - if ( ! empty( $this->entry ) ) { |
|
1439 | - $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;" ) ); |
|
1438 | + if (!empty($this->entry)) { |
|
1439 | + $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;")); |
|
1440 | 1440 | } |
1441 | 1441 | |
1442 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
1442 | + echo GVCommon::generate_notice(wpautop($error), 'gv-error error'); |
|
1443 | 1443 | } |
1444 | 1444 | |
1445 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
1445 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]'.$error); |
|
1446 | 1446 | |
1447 | 1447 | return false; |
1448 | 1448 | } |
@@ -1455,24 +1455,24 @@ discard block |
||
1455 | 1455 | * @param boolean $echo Whether to show error message telling user they aren't allowed |
1456 | 1456 | * @return boolean True: user can edit the current field; False: nope, they can't. |
1457 | 1457 | */ |
1458 | - private function user_can_edit_field( $field, $echo = false ) { |
|
1458 | + private function user_can_edit_field($field, $echo = false) { |
|
1459 | 1459 | |
1460 | 1460 | $error = NULL; |
1461 | 1461 | |
1462 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
1463 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
1462 | + if (!$this->check_user_cap_edit_field($field)) { |
|
1463 | + $error = __('You do not have permission to edit this field.', 'gravityview'); |
|
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | // No errors; everything's fine here! |
1467 | - if( empty( $error ) ) { |
|
1467 | + if (empty($error)) { |
|
1468 | 1468 | return true; |
1469 | 1469 | } |
1470 | 1470 | |
1471 | - if( $echo ) { |
|
1472 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
1471 | + if ($echo) { |
|
1472 | + echo GVCommon::generate_notice(wpautop(esc_html($error)), 'gv-error error'); |
|
1473 | 1473 | } |
1474 | 1474 | |
1475 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
1475 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]'.$error); |
|
1476 | 1476 | |
1477 | 1477 | return false; |
1478 | 1478 | |
@@ -1487,18 +1487,18 @@ discard block |
||
1487 | 1487 | * @param [type] $field [description] |
1488 | 1488 | * @return bool |
1489 | 1489 | */ |
1490 | - private function check_user_cap_edit_field( $field ) { |
|
1490 | + private function check_user_cap_edit_field($field) { |
|
1491 | 1491 | |
1492 | 1492 | // If they can edit any entries (as defined in Gravity Forms), we're good. |
1493 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
1493 | + if (GVCommon::has_cap(array('gravityforms_edit_entries', 'gravityview_edit_others_entries'))) { |
|
1494 | 1494 | return true; |
1495 | 1495 | } |
1496 | 1496 | |
1497 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
1497 | + $field_cap = isset($field['allow_edit_cap']) ? $field['allow_edit_cap'] : false; |
|
1498 | 1498 | |
1499 | 1499 | // If the field has custom editing capaibilities set, check those |
1500 | - if( $field_cap ) { |
|
1501 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
1500 | + if ($field_cap) { |
|
1501 | + return GVCommon::has_cap($field['allow_edit_cap']); |
|
1502 | 1502 | } |
1503 | 1503 | |
1504 | 1504 | return false; |
@@ -1512,17 +1512,17 @@ discard block |
||
1512 | 1512 | public function verify_nonce() { |
1513 | 1513 | |
1514 | 1514 | // Verify form submitted for editing single |
1515 | - if( $this->is_edit_entry_submission() ) { |
|
1516 | - $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
1515 | + if ($this->is_edit_entry_submission()) { |
|
1516 | + $valid = wp_verify_nonce($_POST[self::$nonce_field], self::$nonce_field); |
|
1517 | 1517 | } |
1518 | 1518 | |
1519 | 1519 | // Verify |
1520 | - else if( ! $this->is_edit_entry() ) { |
|
1520 | + else if (!$this->is_edit_entry()) { |
|
1521 | 1521 | $valid = false; |
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | else { |
1525 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
1525 | + $valid = wp_verify_nonce($_GET['edit'], self::$nonce_key); |
|
1526 | 1526 | } |
1527 | 1527 | |
1528 | 1528 | /** |
@@ -1531,7 +1531,7 @@ discard block |
||
1531 | 1531 | * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
1532 | 1532 | * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
1533 | 1533 | */ |
1534 | - $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
1534 | + $valid = apply_filters('gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field); |
|
1535 | 1535 | |
1536 | 1536 | return $valid; |
1537 | 1537 | } |
@@ -1519,9 +1519,7 @@ |
||
1519 | 1519 | // Verify |
1520 | 1520 | else if( ! $this->is_edit_entry() ) { |
1521 | 1521 | $valid = false; |
1522 | - } |
|
1523 | - |
|
1524 | - else { |
|
1522 | + } else { |
|
1525 | 1523 | $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
1526 | 1524 | } |
1527 | 1525 |
@@ -57,7 +57,7 @@ |
||
57 | 57 | * @since 1.11 |
58 | 58 | * |
59 | 59 | * @param array $form Gravity Forms form array |
60 | - * @param string $entry_id Gravity Forms entry ID |
|
60 | + * @param integer $entry_id Gravity Forms entry ID |
|
61 | 61 | * @return void |
62 | 62 | */ |
63 | 63 | public function update_user( $form = array(), $entry_id = 0 ) { |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | if ( ! defined( 'WPINC' ) ) { |
14 | - die; |
|
14 | + die; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
@@ -22,237 +22,237 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @var GravityView_Edit_Entry |
24 | 24 | */ |
25 | - protected $loader; |
|
25 | + protected $loader; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var WP_User|null Temporary storage used by restore_user_details() |
|
29 | - */ |
|
30 | - private $_user_before_update = null; |
|
27 | + /** |
|
28 | + * @var WP_User|null Temporary storage used by restore_user_details() |
|
29 | + */ |
|
30 | + private $_user_before_update = null; |
|
31 | 31 | |
32 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
33 | - $this->loader = $loader; |
|
34 | - } |
|
32 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
33 | + $this->loader = $loader; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @since 1.11 |
38 | 38 | */ |
39 | 39 | public function load() { |
40 | 40 | |
41 | - /** |
|
42 | - * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
43 | - * @since 1.11 |
|
44 | - * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
45 | - */ |
|
46 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
47 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
48 | - |
|
49 | - // last resort in case the current user display name don't match any of the defaults |
|
50 | - add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Update the WordPress user profile based on the GF User Registration create feed |
|
56 | - * |
|
57 | - * @since 1.11 |
|
58 | - * |
|
59 | - * @param array $form Gravity Forms form array |
|
60 | - * @param string $entry_id Gravity Forms entry ID |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function update_user( $form = array(), $entry_id = 0 ) { |
|
64 | - |
|
65 | - if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) { |
|
66 | - return; |
|
67 | - } |
|
68 | - |
|
69 | - $entry = GFAPI::get_entry( $entry_id ); |
|
70 | - |
|
71 | - /** |
|
72 | - * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
73 | - * @since 1.11 |
|
74 | - * @param array $entry Gravity Forms entry |
|
75 | - * @param array $form Gravity Forms form |
|
76 | - */ |
|
77 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
78 | - |
|
79 | - /** |
|
80 | - * @since 1.14 |
|
81 | - */ |
|
82 | - $config = GFUser::get_active_config( $form, $entry ); |
|
83 | - |
|
84 | - /** |
|
85 | - * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
86 | - * @since 1.15 |
|
87 | - * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
88 | - * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
89 | - * @param[in] array $form Gravity Forms form array |
|
90 | - * @param[in] array $entry Gravity Forms entry being edited |
|
91 | - */ |
|
92 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
93 | - |
|
94 | - if( $preserve_role ) { |
|
95 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Make sure the current display name is not changed with the update user method. |
|
100 | - * @since 1.15 |
|
101 | - */ |
|
102 | - $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
107 | - * @since 1.14 |
|
108 | - * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
109 | - * @param[in] array $form Gravity Forms form array |
|
110 | - * @param[in] array $entry Gravity Forms entry being edited |
|
111 | - */ |
|
112 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
113 | - |
|
114 | - $is_create_feed = ( $config && rgars( $config, 'meta/feed_type') === 'create' ); |
|
115 | - |
|
116 | - // Only update if it's a create feed |
|
117 | - if( ! $is_create_feed ) { |
|
118 | - return; |
|
119 | - } |
|
120 | - |
|
121 | - // The priority is set to 3 so that default priority (10) will still override it |
|
122 | - add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
123 | - add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
124 | - |
|
125 | - // Trigger the User Registration update user method |
|
126 | - GFUser::update_user( $entry, $form, $config ); |
|
127 | - |
|
128 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
129 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
130 | - |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Calculate the user display name format |
|
135 | - * |
|
136 | - * @since 1.15 |
|
137 | - * |
|
138 | - * @param int $user_id WP User ID |
|
139 | - * @return string Display name format as used inside Gravity Forms User Registration |
|
140 | - */ |
|
141 | - public function match_current_display_name( $user_id ) { |
|
142 | - |
|
143 | - $user = get_userdata( $user_id ); |
|
144 | - |
|
145 | - $names = $this->generate_display_names( $user ); |
|
146 | - |
|
147 | - $format = array_search( $user->display_name, $names, true ); |
|
148 | - |
|
149 | - // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) |
|
150 | - // trigger last resort method at the 'gform_user_updated' hook |
|
151 | - if( false === $format || 'nickname' === $format ) { |
|
152 | - $this->_user_before_update = $user; |
|
153 | - $format = 'nickname'; |
|
154 | - } |
|
155 | - |
|
156 | - return $format; |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Generate an array of all the user display names possibilities |
|
162 | - * |
|
163 | - * @since 1.15 |
|
164 | - * |
|
165 | - * @param object $profileuser WP_User object |
|
166 | - * @return array List all the possible display names for a certain User object |
|
167 | - */ |
|
168 | - public function generate_display_names( $profileuser ) { |
|
169 | - |
|
170 | - $public_display = array(); |
|
171 | - $public_display['nickname'] = $profileuser->nickname; |
|
172 | - $public_display['username'] = $profileuser->user_login; |
|
173 | - |
|
174 | - if ( !empty($profileuser->first_name) ) |
|
175 | - $public_display['firstname'] = $profileuser->first_name; |
|
176 | - |
|
177 | - if ( !empty($profileuser->last_name) ) |
|
178 | - $public_display['lastname'] = $profileuser->last_name; |
|
179 | - |
|
180 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
181 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
182 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
183 | - } |
|
184 | - |
|
185 | - $public_display = array_map( 'trim', $public_display ); |
|
186 | - $public_display = array_unique( $public_display ); |
|
187 | - |
|
188 | - return $public_display; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
194 | - * |
|
195 | - * @see GFUser::update_user() |
|
196 | - * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
197 | - * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
198 | - * @param array $entry The Gravity Forms entry that was just updated |
|
199 | - * @param string $password User password |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
203 | - |
|
204 | - /** |
|
205 | - * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
206 | - * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
207 | - * @since 1.14.4 |
|
208 | - * @param boolean $restore_display_name Restore Display Name? Default: true |
|
209 | - */ |
|
210 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
211 | - |
|
212 | - $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
213 | - |
|
214 | - /** |
|
215 | - * Don't restore display name: |
|
216 | - * - either disabled, |
|
217 | - * - or it is an Update feed (we only care about Create feed) |
|
218 | - * - or we don't need as we found the correct format before updating user. |
|
219 | - * @since 1.14.4 |
|
220 | - */ |
|
221 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
222 | - return; |
|
223 | - } |
|
224 | - |
|
225 | - $user_after_update = get_userdata( $user_id ); |
|
226 | - |
|
227 | - $restored_user = $user_after_update; |
|
228 | - |
|
229 | - // Restore previous display_name |
|
230 | - $restored_user->display_name = $this->_user_before_update->display_name; |
|
231 | - |
|
232 | - // Don't have WP update the password. |
|
233 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
234 | - |
|
235 | - /** |
|
236 | - * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
237 | - * @since 1.14 |
|
238 | - * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
239 | - * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
240 | - * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
241 | - * @param array $entry The Gravity Forms entry that was just updated |
|
242 | - */ |
|
243 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
244 | - |
|
245 | - $updated = wp_update_user( $restored_user ); |
|
246 | - |
|
247 | - if( is_wp_error( $updated ) ) { |
|
248 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
249 | - } else { |
|
250 | - do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
251 | - } |
|
252 | - |
|
253 | - $this->_user_before_update = null; |
|
254 | - |
|
255 | - unset( $updated, $restored_user, $user_after_update ); |
|
256 | - } |
|
41 | + /** |
|
42 | + * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
43 | + * @since 1.11 |
|
44 | + * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
45 | + */ |
|
46 | + if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
47 | + add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
48 | + |
|
49 | + // last resort in case the current user display name don't match any of the defaults |
|
50 | + add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Update the WordPress user profile based on the GF User Registration create feed |
|
56 | + * |
|
57 | + * @since 1.11 |
|
58 | + * |
|
59 | + * @param array $form Gravity Forms form array |
|
60 | + * @param string $entry_id Gravity Forms entry ID |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function update_user( $form = array(), $entry_id = 0 ) { |
|
64 | + |
|
65 | + if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) { |
|
66 | + return; |
|
67 | + } |
|
68 | + |
|
69 | + $entry = GFAPI::get_entry( $entry_id ); |
|
70 | + |
|
71 | + /** |
|
72 | + * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
73 | + * @since 1.11 |
|
74 | + * @param array $entry Gravity Forms entry |
|
75 | + * @param array $form Gravity Forms form |
|
76 | + */ |
|
77 | + $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
78 | + |
|
79 | + /** |
|
80 | + * @since 1.14 |
|
81 | + */ |
|
82 | + $config = GFUser::get_active_config( $form, $entry ); |
|
83 | + |
|
84 | + /** |
|
85 | + * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
86 | + * @since 1.15 |
|
87 | + * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
88 | + * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
89 | + * @param[in] array $form Gravity Forms form array |
|
90 | + * @param[in] array $entry Gravity Forms entry being edited |
|
91 | + */ |
|
92 | + $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
93 | + |
|
94 | + if( $preserve_role ) { |
|
95 | + $config['meta']['role'] = 'gfur_preserve_role'; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Make sure the current display name is not changed with the update user method. |
|
100 | + * @since 1.15 |
|
101 | + */ |
|
102 | + $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
107 | + * @since 1.14 |
|
108 | + * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
109 | + * @param[in] array $form Gravity Forms form array |
|
110 | + * @param[in] array $entry Gravity Forms entry being edited |
|
111 | + */ |
|
112 | + $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
113 | + |
|
114 | + $is_create_feed = ( $config && rgars( $config, 'meta/feed_type') === 'create' ); |
|
115 | + |
|
116 | + // Only update if it's a create feed |
|
117 | + if( ! $is_create_feed ) { |
|
118 | + return; |
|
119 | + } |
|
120 | + |
|
121 | + // The priority is set to 3 so that default priority (10) will still override it |
|
122 | + add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
123 | + add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
124 | + |
|
125 | + // Trigger the User Registration update user method |
|
126 | + GFUser::update_user( $entry, $form, $config ); |
|
127 | + |
|
128 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
129 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
130 | + |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Calculate the user display name format |
|
135 | + * |
|
136 | + * @since 1.15 |
|
137 | + * |
|
138 | + * @param int $user_id WP User ID |
|
139 | + * @return string Display name format as used inside Gravity Forms User Registration |
|
140 | + */ |
|
141 | + public function match_current_display_name( $user_id ) { |
|
142 | + |
|
143 | + $user = get_userdata( $user_id ); |
|
144 | + |
|
145 | + $names = $this->generate_display_names( $user ); |
|
146 | + |
|
147 | + $format = array_search( $user->display_name, $names, true ); |
|
148 | + |
|
149 | + // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) |
|
150 | + // trigger last resort method at the 'gform_user_updated' hook |
|
151 | + if( false === $format || 'nickname' === $format ) { |
|
152 | + $this->_user_before_update = $user; |
|
153 | + $format = 'nickname'; |
|
154 | + } |
|
155 | + |
|
156 | + return $format; |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Generate an array of all the user display names possibilities |
|
162 | + * |
|
163 | + * @since 1.15 |
|
164 | + * |
|
165 | + * @param object $profileuser WP_User object |
|
166 | + * @return array List all the possible display names for a certain User object |
|
167 | + */ |
|
168 | + public function generate_display_names( $profileuser ) { |
|
169 | + |
|
170 | + $public_display = array(); |
|
171 | + $public_display['nickname'] = $profileuser->nickname; |
|
172 | + $public_display['username'] = $profileuser->user_login; |
|
173 | + |
|
174 | + if ( !empty($profileuser->first_name) ) |
|
175 | + $public_display['firstname'] = $profileuser->first_name; |
|
176 | + |
|
177 | + if ( !empty($profileuser->last_name) ) |
|
178 | + $public_display['lastname'] = $profileuser->last_name; |
|
179 | + |
|
180 | + if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
181 | + $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
182 | + $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
183 | + } |
|
184 | + |
|
185 | + $public_display = array_map( 'trim', $public_display ); |
|
186 | + $public_display = array_unique( $public_display ); |
|
187 | + |
|
188 | + return $public_display; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
194 | + * |
|
195 | + * @see GFUser::update_user() |
|
196 | + * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
197 | + * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
198 | + * @param array $entry The Gravity Forms entry that was just updated |
|
199 | + * @param string $password User password |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
203 | + |
|
204 | + /** |
|
205 | + * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
206 | + * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
207 | + * @since 1.14.4 |
|
208 | + * @param boolean $restore_display_name Restore Display Name? Default: true |
|
209 | + */ |
|
210 | + $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
211 | + |
|
212 | + $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
213 | + |
|
214 | + /** |
|
215 | + * Don't restore display name: |
|
216 | + * - either disabled, |
|
217 | + * - or it is an Update feed (we only care about Create feed) |
|
218 | + * - or we don't need as we found the correct format before updating user. |
|
219 | + * @since 1.14.4 |
|
220 | + */ |
|
221 | + if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
222 | + return; |
|
223 | + } |
|
224 | + |
|
225 | + $user_after_update = get_userdata( $user_id ); |
|
226 | + |
|
227 | + $restored_user = $user_after_update; |
|
228 | + |
|
229 | + // Restore previous display_name |
|
230 | + $restored_user->display_name = $this->_user_before_update->display_name; |
|
231 | + |
|
232 | + // Don't have WP update the password. |
|
233 | + unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
234 | + |
|
235 | + /** |
|
236 | + * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
237 | + * @since 1.14 |
|
238 | + * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
239 | + * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
240 | + * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
241 | + * @param array $entry The Gravity Forms entry that was just updated |
|
242 | + */ |
|
243 | + $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
244 | + |
|
245 | + $updated = wp_update_user( $restored_user ); |
|
246 | + |
|
247 | + if( is_wp_error( $updated ) ) { |
|
248 | + do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
249 | + } else { |
|
250 | + do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
251 | + } |
|
252 | + |
|
253 | + $this->_user_before_update = null; |
|
254 | + |
|
255 | + unset( $updated, $restored_user, $user_after_update ); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | } //end class |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @copyright Copyright 2015, Katz Web Services, Inc. |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'WPINC' ) ) { |
|
13 | +if (!defined('WPINC')) { |
|
14 | 14 | die; |
15 | 15 | } |
16 | 16 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | private $_user_before_update = null; |
31 | 31 | |
32 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
32 | + function __construct(GravityView_Edit_Entry $loader) { |
|
33 | 33 | $this->loader = $loader; |
34 | 34 | } |
35 | 35 | |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | * @since 1.11 |
44 | 44 | * @param boolean $boolean Whether to trigger update on user registration (default: true) |
45 | 45 | */ |
46 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
47 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
46 | + if (apply_filters('gravityview/edit_entry/user_registration/trigger_update', true)) { |
|
47 | + add_action('gravityview/edit_entry/after_update', array($this, 'update_user'), 10, 2); |
|
48 | 48 | |
49 | 49 | // last resort in case the current user display name don't match any of the defaults |
50 | - add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
50 | + add_action('gform_user_updated', array($this, 'restore_display_name'), 10, 4); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | * @param string $entry_id Gravity Forms entry ID |
61 | 61 | * @return void |
62 | 62 | */ |
63 | - public function update_user( $form = array(), $entry_id = 0 ) { |
|
63 | + public function update_user($form = array(), $entry_id = 0) { |
|
64 | 64 | |
65 | - if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) { |
|
65 | + if (!class_exists('GFAPI') || !class_exists('GFUser') || empty($entry_id)) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - $entry = GFAPI::get_entry( $entry_id ); |
|
69 | + $entry = GFAPI::get_entry($entry_id); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | * @param array $entry Gravity Forms entry |
75 | 75 | * @param array $form Gravity Forms form |
76 | 76 | */ |
77 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
77 | + $entry = apply_filters('gravityview/edit_entry/user_registration/entry', $entry, $form); |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @since 1.14 |
81 | 81 | */ |
82 | - $config = GFUser::get_active_config( $form, $entry ); |
|
82 | + $config = GFUser::get_active_config($form, $entry); |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | * @param[in] array $form Gravity Forms form array |
90 | 90 | * @param[in] array $entry Gravity Forms entry being edited |
91 | 91 | */ |
92 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
92 | + $preserve_role = apply_filters('gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry); |
|
93 | 93 | |
94 | - if( $preserve_role ) { |
|
94 | + if ($preserve_role) { |
|
95 | 95 | $config['meta']['role'] = 'gfur_preserve_role'; |
96 | 96 | } |
97 | 97 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * Make sure the current display name is not changed with the update user method. |
100 | 100 | * @since 1.15 |
101 | 101 | */ |
102 | - $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); |
|
102 | + $config['meta']['displayname'] = $this->match_current_display_name($entry['created_by']); |
|
103 | 103 | |
104 | 104 | |
105 | 105 | /** |
@@ -109,24 +109,24 @@ discard block |
||
109 | 109 | * @param[in] array $form Gravity Forms form array |
110 | 110 | * @param[in] array $entry Gravity Forms entry being edited |
111 | 111 | */ |
112 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
112 | + $config = apply_filters('gravityview/edit_entry/user_registration/config', $config, $form, $entry); |
|
113 | 113 | |
114 | - $is_create_feed = ( $config && rgars( $config, 'meta/feed_type') === 'create' ); |
|
114 | + $is_create_feed = ($config && rgars($config, 'meta/feed_type') === 'create'); |
|
115 | 115 | |
116 | 116 | // Only update if it's a create feed |
117 | - if( ! $is_create_feed ) { |
|
117 | + if (!$is_create_feed) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // The priority is set to 3 so that default priority (10) will still override it |
122 | - add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
123 | - add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
122 | + add_filter('send_password_change_email', '__return_false', 3); |
|
123 | + add_filter('send_email_change_email', '__return_false', 3); |
|
124 | 124 | |
125 | 125 | // Trigger the User Registration update user method |
126 | - GFUser::update_user( $entry, $form, $config ); |
|
126 | + GFUser::update_user($entry, $form, $config); |
|
127 | 127 | |
128 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
129 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
128 | + remove_filter('send_password_change_email', '__return_false', 3); |
|
129 | + remove_filter('send_email_change_email', '__return_false', 3); |
|
130 | 130 | |
131 | 131 | } |
132 | 132 | |
@@ -138,17 +138,17 @@ discard block |
||
138 | 138 | * @param int $user_id WP User ID |
139 | 139 | * @return string Display name format as used inside Gravity Forms User Registration |
140 | 140 | */ |
141 | - public function match_current_display_name( $user_id ) { |
|
141 | + public function match_current_display_name($user_id) { |
|
142 | 142 | |
143 | - $user = get_userdata( $user_id ); |
|
143 | + $user = get_userdata($user_id); |
|
144 | 144 | |
145 | - $names = $this->generate_display_names( $user ); |
|
145 | + $names = $this->generate_display_names($user); |
|
146 | 146 | |
147 | - $format = array_search( $user->display_name, $names, true ); |
|
147 | + $format = array_search($user->display_name, $names, true); |
|
148 | 148 | |
149 | 149 | // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) |
150 | 150 | // trigger last resort method at the 'gform_user_updated' hook |
151 | - if( false === $format || 'nickname' === $format ) { |
|
151 | + if (false === $format || 'nickname' === $format) { |
|
152 | 152 | $this->_user_before_update = $user; |
153 | 153 | $format = 'nickname'; |
154 | 154 | } |
@@ -165,25 +165,25 @@ discard block |
||
165 | 165 | * @param object $profileuser WP_User object |
166 | 166 | * @return array List all the possible display names for a certain User object |
167 | 167 | */ |
168 | - public function generate_display_names( $profileuser ) { |
|
168 | + public function generate_display_names($profileuser) { |
|
169 | 169 | |
170 | 170 | $public_display = array(); |
171 | 171 | $public_display['nickname'] = $profileuser->nickname; |
172 | 172 | $public_display['username'] = $profileuser->user_login; |
173 | 173 | |
174 | - if ( !empty($profileuser->first_name) ) |
|
174 | + if (!empty($profileuser->first_name)) |
|
175 | 175 | $public_display['firstname'] = $profileuser->first_name; |
176 | 176 | |
177 | - if ( !empty($profileuser->last_name) ) |
|
177 | + if (!empty($profileuser->last_name)) |
|
178 | 178 | $public_display['lastname'] = $profileuser->last_name; |
179 | 179 | |
180 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
181 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
182 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
180 | + if (!empty($profileuser->first_name) && !empty($profileuser->last_name)) { |
|
181 | + $public_display['firstlast'] = $profileuser->first_name.' '.$profileuser->last_name; |
|
182 | + $public_display['lastfirst'] = $profileuser->last_name.' '.$profileuser->first_name; |
|
183 | 183 | } |
184 | 184 | |
185 | - $public_display = array_map( 'trim', $public_display ); |
|
186 | - $public_display = array_unique( $public_display ); |
|
185 | + $public_display = array_map('trim', $public_display); |
|
186 | + $public_display = array_unique($public_display); |
|
187 | 187 | |
188 | 188 | return $public_display; |
189 | 189 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @param string $password User password |
200 | 200 | * @return void |
201 | 201 | */ |
202 | - public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
202 | + public function restore_display_name($user_id = 0, $config = array(), $entry = array(), $password = '') { |
|
203 | 203 | |
204 | 204 | /** |
205 | 205 | * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
@@ -207,9 +207,9 @@ discard block |
||
207 | 207 | * @since 1.14.4 |
208 | 208 | * @param boolean $restore_display_name Restore Display Name? Default: true |
209 | 209 | */ |
210 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
210 | + $restore_display_name = apply_filters('gravityview/edit_entry/restore_display_name', true); |
|
211 | 211 | |
212 | - $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
212 | + $is_update_feed = ($config && rgars($config, 'meta/feed_type') === 'update'); |
|
213 | 213 | |
214 | 214 | /** |
215 | 215 | * Don't restore display name: |
@@ -218,11 +218,11 @@ discard block |
||
218 | 218 | * - or we don't need as we found the correct format before updating user. |
219 | 219 | * @since 1.14.4 |
220 | 220 | */ |
221 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
221 | + if (!$restore_display_name || $is_update_feed || is_null($this->_user_before_update)) { |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
225 | - $user_after_update = get_userdata( $user_id ); |
|
225 | + $user_after_update = get_userdata($user_id); |
|
226 | 226 | |
227 | 227 | $restored_user = $user_after_update; |
228 | 228 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $restored_user->display_name = $this->_user_before_update->display_name; |
231 | 231 | |
232 | 232 | // Don't have WP update the password. |
233 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
233 | + unset($restored_user->data->user_pass, $restored_user->user_pass); |
|
234 | 234 | |
235 | 235 | /** |
236 | 236 | * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
241 | 241 | * @param array $entry The Gravity Forms entry that was just updated |
242 | 242 | */ |
243 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
243 | + $restored_user = apply_filters('gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry); |
|
244 | 244 | |
245 | - $updated = wp_update_user( $restored_user ); |
|
245 | + $updated = wp_update_user($restored_user); |
|
246 | 246 | |
247 | - if( is_wp_error( $updated ) ) { |
|
248 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
247 | + if (is_wp_error($updated)) { |
|
248 | + do_action('gravityview_log_error', __METHOD__.sprintf(' - There was an error updating user #%d details', $user_id), $updated); |
|
249 | 249 | } else { |
250 | - do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
250 | + do_action('gravityview_log_debug', __METHOD__.sprintf(' - User #%d details restored', $user_id)); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | $this->_user_before_update = null; |
254 | 254 | |
255 | - unset( $updated, $restored_user, $user_after_update ); |
|
255 | + unset($updated, $restored_user, $user_after_update); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } //end class |
@@ -171,11 +171,13 @@ |
||
171 | 171 | $public_display['nickname'] = $profileuser->nickname; |
172 | 172 | $public_display['username'] = $profileuser->user_login; |
173 | 173 | |
174 | - if ( !empty($profileuser->first_name) ) |
|
175 | - $public_display['firstname'] = $profileuser->first_name; |
|
174 | + if ( !empty($profileuser->first_name) ) { |
|
175 | + $public_display['firstname'] = $profileuser->first_name; |
|
176 | + } |
|
176 | 177 | |
177 | - if ( !empty($profileuser->last_name) ) |
|
178 | - $public_display['lastname'] = $profileuser->last_name; |
|
178 | + if ( !empty($profileuser->last_name) ) { |
|
179 | + $public_display['lastname'] = $profileuser->last_name; |
|
180 | + } |
|
179 | 181 | |
180 | 182 | if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
181 | 183 | $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |