@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | wp_nonce_field( 'gravityview_select_form', 'gravityview_select_form_nonce' ); |
| 12 | 12 | |
| 13 | 13 | //current value |
| 14 | -$current_form = (int) rgar( (array) $_GET, 'form_id', gravityview_get_form_id( $post->ID ) ); |
|
| 14 | +$current_form = (int)rgar( (array)$_GET, 'form_id', gravityview_get_form_id( $post->ID ) ); |
|
| 15 | 15 | |
| 16 | 16 | // check for available gravity forms |
| 17 | 17 | $forms = gravityview_get_forms(); |
@@ -26,24 +26,24 @@ discard block |
||
| 26 | 26 | ?> |
| 27 | 27 | <a class="button button-primary" href="#gv_start_fresh" title="<?php esc_attr_e( 'Start Fresh', 'gravityview' ); ?>"><?php esc_html_e( 'Start Fresh', 'gravityview' ); ?></a> |
| 28 | 28 | |
| 29 | - <?php if( !empty( $forms ) ) { ?> |
|
| 29 | + <?php if ( ! empty( $forms ) ) { ?> |
|
| 30 | 30 | <span> <?php esc_html_e( 'or use an existing form', 'gravityview' ); ?> </span> |
| 31 | 31 | <?php } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // If there are no forms to select, show no forms. |
| 35 | - if( !empty( $forms ) ) { ?> |
|
| 35 | + if ( ! empty( $forms ) ) { ?> |
|
| 36 | 36 | <select name="gravityview_form_id" id="gravityview_form_id"> |
| 37 | 37 | <option value="" <?php selected( '', $current_form, true ); ?>>— <?php esc_html_e( 'list of forms', 'gravityview' ); ?> —</option> |
| 38 | - <?php foreach( $forms as $form ) { ?> |
|
| 39 | - <option value="<?php echo $form['id']; ?>" <?php selected( $form['id'], $current_form, true ); ?>><?php echo esc_html( $form['title'] ); ?></option> |
|
| 38 | + <?php foreach ( $forms as $form ) { ?> |
|
| 39 | + <option value="<?php echo $form[ 'id' ]; ?>" <?php selected( $form[ 'id' ], $current_form, true ); ?>><?php echo esc_html( $form[ 'title' ] ); ?></option> |
|
| 40 | 40 | <?php } ?> |
| 41 | 41 | </select> |
| 42 | 42 | <?php } else { ?> |
| 43 | 43 | <select name="gravityview_form_id" id="gravityview_form_id" class="hidden"><option selected="selected" value=""></option></select> |
| 44 | 44 | <?php } ?> |
| 45 | 45 | |
| 46 | - <a class="button button-primary" <?php if( empty( $current_form ) ) { echo 'style="display:none;"'; } ?> id="gv_switch_view_button" href="#gv_switch_view" title="<?php esc_attr_e( 'Switch View', 'gravityview' ); ?>"><?php esc_html_e( 'Switch View Type', 'gravityview' ); ?></a> |
|
| 46 | + <a class="button button-primary" <?php if ( empty( $current_form ) ) { echo 'style="display:none;"'; } ?> id="gv_switch_view_button" href="#gv_switch_view" title="<?php esc_attr_e( 'Switch View', 'gravityview' ); ?>"><?php esc_html_e( 'Switch View Type', 'gravityview' ); ?></a> |
|
| 47 | 47 | </p> |
| 48 | 48 | |
| 49 | 49 | <?php // confirm dialog box ?> |
@@ -5,220 +5,220 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class GravityView_Change_Entry_Creator { |
| 7 | 7 | |
| 8 | - function __construct() { |
|
| 9 | - |
|
| 10 | - /** |
|
| 11 | - * @since 1.5.1 |
|
| 12 | - */ |
|
| 13 | - add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 ); |
|
| 14 | - |
|
| 15 | - // ONLY ADMIN FROM HERE ON. |
|
| 16 | - if( !is_admin() ) { return; } |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality |
|
| 20 | - * @since 1.7.4 |
|
| 21 | - * @param boolean $disable Disable the Change Entry Creator functionality. Default: false. |
|
| 22 | - */ |
|
| 23 | - if( apply_filters('gravityview_disable_change_entry_creator', false ) ) { |
|
| 24 | - return; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Use `init` to fix bbPress warning |
|
| 29 | - * @see https://bbpress.trac.wordpress.org/ticket/2309 |
|
| 30 | - */ |
|
| 31 | - add_action('init', array( $this, 'load'), 100 ); |
|
| 32 | - |
|
| 33 | - add_action('plugins_loaded', array( $this, 'prevent_conflicts') ); |
|
| 8 | + function __construct() { |
|
| 9 | + |
|
| 10 | + /** |
|
| 11 | + * @since 1.5.1 |
|
| 12 | + */ |
|
| 13 | + add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 ); |
|
| 14 | + |
|
| 15 | + // ONLY ADMIN FROM HERE ON. |
|
| 16 | + if( !is_admin() ) { return; } |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality |
|
| 20 | + * @since 1.7.4 |
|
| 21 | + * @param boolean $disable Disable the Change Entry Creator functionality. Default: false. |
|
| 22 | + */ |
|
| 23 | + if( apply_filters('gravityview_disable_change_entry_creator', false ) ) { |
|
| 24 | + return; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Use `init` to fix bbPress warning |
|
| 29 | + * @see https://bbpress.trac.wordpress.org/ticket/2309 |
|
| 30 | + */ |
|
| 31 | + add_action('init', array( $this, 'load'), 100 ); |
|
| 32 | + |
|
| 33 | + add_action('plugins_loaded', array( $this, 'prevent_conflicts') ); |
|
| 34 | 34 | |
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * When an user is created using the User Registration add-on, assign the entry to them |
|
| 39 | - * |
|
| 40 | - * @since 1.5.1 |
|
| 41 | - * @uses RGFormsModel::update_lead_property() Modify the entry `created_by` field |
|
| 42 | - * @param int $user_id WordPress User ID |
|
| 43 | - * @param array $config User registration feed configuration |
|
| 44 | - * @param array $entry GF Entry array |
|
| 45 | - * @param string $password User password |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - function assign_new_user_to_lead( $user_id, $config, $entry = array(), $password = '' ) { |
|
| 37 | + /** |
|
| 38 | + * When an user is created using the User Registration add-on, assign the entry to them |
|
| 39 | + * |
|
| 40 | + * @since 1.5.1 |
|
| 41 | + * @uses RGFormsModel::update_lead_property() Modify the entry `created_by` field |
|
| 42 | + * @param int $user_id WordPress User ID |
|
| 43 | + * @param array $config User registration feed configuration |
|
| 44 | + * @param array $entry GF Entry array |
|
| 45 | + * @param string $password User password |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + function assign_new_user_to_lead( $user_id, $config, $entry = array(), $password = '' ) { |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Disable assigning the new user to the entry by returning false. |
|
| 52 | - * @param int $user_id WordPress User ID |
|
| 53 | - * @param array $config User registration feed configuration |
|
| 54 | - * @param array $entry GF Entry array |
|
| 55 | - */ |
|
| 56 | - $assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry ); |
|
| 57 | - |
|
| 58 | - // If filter returns false, do not process |
|
| 59 | - if( empty( $assign_to_lead ) ) { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 50 | + /** |
|
| 51 | + * Disable assigning the new user to the entry by returning false. |
|
| 52 | + * @param int $user_id WordPress User ID |
|
| 53 | + * @param array $config User registration feed configuration |
|
| 54 | + * @param array $entry GF Entry array |
|
| 55 | + */ |
|
| 56 | + $assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry ); |
|
| 57 | + |
|
| 58 | + // If filter returns false, do not process |
|
| 59 | + if( empty( $assign_to_lead ) ) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - // Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing |
|
| 64 | - $result = RGFormsModel::update_lead_property( $entry['id'], 'created_by', $user_id, false, true ); |
|
| 63 | + // Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing |
|
| 64 | + $result = RGFormsModel::update_lead_property( $entry['id'], 'created_by', $user_id, false, true ); |
|
| 65 | 65 | |
| 66 | - if( empty( $result ) ) { |
|
| 67 | - $status = __('Error', 'gravityview'); |
|
| 68 | - } else { |
|
| 69 | - $status = __('Success', 'gravityview'); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id ); |
|
| 66 | + if( empty( $result ) ) { |
|
| 67 | + $status = __('Error', 'gravityview'); |
|
| 68 | + } else { |
|
| 69 | + $status = __('Success', 'gravityview'); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id ); |
|
| 73 | 73 | |
| 74 | - do_action( 'gravityview_log_debug', 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - '.$note ); |
|
| 74 | + do_action( 'gravityview_log_debug', 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - '.$note ); |
|
| 75 | 75 | |
| 76 | - GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' ); |
|
| 76 | + GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' ); |
|
| 77 | 77 | |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Disable previous functionality; use this one as the canonical. |
|
| 82 | - * @return void |
|
| 83 | - */ |
|
| 84 | - function prevent_conflicts() { |
|
| 80 | + /** |
|
| 81 | + * Disable previous functionality; use this one as the canonical. |
|
| 82 | + * @return void |
|
| 83 | + */ |
|
| 84 | + function prevent_conflicts() { |
|
| 85 | 85 | |
| 86 | - // Plugin that was provided here: |
|
| 87 | - // @link https://gravityview.co/support/documentation/201991205/ |
|
| 88 | - remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 ); |
|
| 89 | - remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 ); |
|
| 86 | + // Plugin that was provided here: |
|
| 87 | + // @link https://gravityview.co/support/documentation/201991205/ |
|
| 88 | + remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 ); |
|
| 89 | + remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 ); |
|
| 90 | 90 | |
| 91 | - // Disable for Gravity Forms Add-ons 3.6.2 and lower |
|
| 92 | - if( class_exists( 'KWS_GF_Change_Lead_Creator' ) ) { |
|
| 91 | + // Disable for Gravity Forms Add-ons 3.6.2 and lower |
|
| 92 | + if( class_exists( 'KWS_GF_Change_Lead_Creator' ) ) { |
|
| 93 | 93 | |
| 94 | - $Old_Lead_Creator = new KWS_GF_Change_Lead_Creator; |
|
| 94 | + $Old_Lead_Creator = new KWS_GF_Change_Lead_Creator; |
|
| 95 | 95 | |
| 96 | - // Now, no validation is required in the methods; let's hook in. |
|
| 97 | - remove_action('admin_init', array( $Old_Lead_Creator, 'set_screen_mode' ) ); |
|
| 96 | + // Now, no validation is required in the methods; let's hook in. |
|
| 97 | + remove_action('admin_init', array( $Old_Lead_Creator, 'set_screen_mode' ) ); |
|
| 98 | 98 | |
| 99 | - remove_action("gform_entry_info", array( $Old_Lead_Creator, 'add_select' ), 10 ); |
|
| 99 | + remove_action("gform_entry_info", array( $Old_Lead_Creator, 'add_select' ), 10 ); |
|
| 100 | 100 | |
| 101 | - remove_action("gform_after_update_entry", array( $Old_Lead_Creator, 'update_entry_creator' ), 10 ); |
|
| 102 | - } |
|
| 101 | + remove_action("gform_after_update_entry", array( $Old_Lead_Creator, 'update_entry_creator' ), 10 ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @since 3.6.3 |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - function load() { |
|
| 106 | + /** |
|
| 107 | + * @since 3.6.3 |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + function load() { |
|
| 111 | 111 | |
| 112 | - // Does GF exist? |
|
| 113 | - if( !class_exists('GFCommon') ) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 112 | + // Does GF exist? |
|
| 113 | + if( !class_exists('GFCommon') ) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - // Can the user edit entries? |
|
| 118 | - if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) { |
|
| 119 | - return; |
|
| 120 | - } |
|
| 117 | + // Can the user edit entries? |
|
| 118 | + if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) { |
|
| 119 | + return; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - // If screen mode isn't set, then we're in the wrong place. |
|
| 123 | - if( empty( $_REQUEST['screen_mode'] ) ) { |
|
| 124 | - return; |
|
| 125 | - } |
|
| 122 | + // If screen mode isn't set, then we're in the wrong place. |
|
| 123 | + if( empty( $_REQUEST['screen_mode'] ) ) { |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - // Now, no validation is required in the methods; let's hook in. |
|
| 128 | - add_action('admin_init', array( &$this, 'set_screen_mode' ) ); |
|
| 127 | + // Now, no validation is required in the methods; let's hook in. |
|
| 128 | + add_action('admin_init', array( &$this, 'set_screen_mode' ) ); |
|
| 129 | 129 | |
| 130 | - add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2); |
|
| 130 | + add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2); |
|
| 131 | 131 | |
| 132 | - add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2); |
|
| 132 | + add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2); |
|
| 133 | 133 | |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Allows for edit links to work with a link instead of a form (GET instead of POST) |
|
| 138 | - * @return void |
|
| 139 | - */ |
|
| 140 | - function set_screen_mode() { |
|
| 136 | + /** |
|
| 137 | + * Allows for edit links to work with a link instead of a form (GET instead of POST) |
|
| 138 | + * @return void |
|
| 139 | + */ |
|
| 140 | + function set_screen_mode() { |
|
| 141 | 141 | |
| 142 | - // If $_GET['screen_mode'] is set to edit, set $_POST value |
|
| 143 | - if( rgget('screen_mode') === 'edit' ) { |
|
| 144 | - $_POST["screen_mode"] = 'edit'; |
|
| 145 | - } |
|
| 142 | + // If $_GET['screen_mode'] is set to edit, set $_POST value |
|
| 143 | + if( rgget('screen_mode') === 'edit' ) { |
|
| 144 | + $_POST["screen_mode"] = 'edit'; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * When the entry creator is changed, add a note to the entry |
|
| 151 | - * @param array $form GF entry array |
|
| 152 | - * @param int $entry_id Entry ID |
|
| 153 | - * @return void |
|
| 154 | - */ |
|
| 155 | - function update_entry_creator($form, $entry_id) { |
|
| 156 | - global $current_user; |
|
| 149 | + /** |
|
| 150 | + * When the entry creator is changed, add a note to the entry |
|
| 151 | + * @param array $form GF entry array |
|
| 152 | + * @param int $entry_id Entry ID |
|
| 153 | + * @return void |
|
| 154 | + */ |
|
| 155 | + function update_entry_creator($form, $entry_id) { |
|
| 156 | + global $current_user; |
|
| 157 | 157 | |
| 158 | - // Update the entry |
|
| 159 | - $created_by = absint( rgpost('created_by') ); |
|
| 158 | + // Update the entry |
|
| 159 | + $created_by = absint( rgpost('created_by') ); |
|
| 160 | 160 | |
| 161 | - RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by ); |
|
| 161 | + RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by ); |
|
| 162 | 162 | |
| 163 | - // If the creator has changed, let's add a note about who it used to be. |
|
| 164 | - $originally_created_by = rgpost('originally_created_by'); |
|
| 163 | + // If the creator has changed, let's add a note about who it used to be. |
|
| 164 | + $originally_created_by = rgpost('originally_created_by'); |
|
| 165 | 165 | |
| 166 | - // If there's no owner and there didn't used to be, keep going |
|
| 167 | - if( empty( $originally_created_by ) && empty( $created_by ) ) { |
|
| 168 | - return; |
|
| 169 | - } |
|
| 166 | + // If there's no owner and there didn't used to be, keep going |
|
| 167 | + if( empty( $originally_created_by ) && empty( $created_by ) ) { |
|
| 168 | + return; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - // If the values have changed |
|
| 172 | - if( absint( $originally_created_by ) !== absint( $created_by ) ) { |
|
| 171 | + // If the values have changed |
|
| 172 | + if( absint( $originally_created_by ) !== absint( $created_by ) ) { |
|
| 173 | 173 | |
| 174 | - $user_data = get_userdata($current_user->ID); |
|
| 174 | + $user_data = get_userdata($current_user->ID); |
|
| 175 | 175 | |
| 176 | - $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview'); |
|
| 176 | + $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview'); |
|
| 177 | 177 | |
| 178 | - $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview'); |
|
| 178 | + $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview'); |
|
| 179 | 179 | |
| 180 | - if( !empty( $originally_created_by ) ) { |
|
| 181 | - $originally_created_by_user_data = get_userdata($originally_created_by); |
|
| 182 | - $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID ); |
|
| 183 | - } |
|
| 180 | + if( !empty( $originally_created_by ) ) { |
|
| 181 | + $originally_created_by_user_data = get_userdata($originally_created_by); |
|
| 182 | + $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - if( !empty( $created_by ) ) { |
|
| 186 | - $created_by_user_data = get_userdata($created_by); |
|
| 187 | - $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID ); |
|
| 188 | - } |
|
| 185 | + if( !empty( $created_by ) ) { |
|
| 186 | + $created_by_user_data = get_userdata($created_by); |
|
| 187 | + $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID ); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' ); |
|
| 191 | - } |
|
| 190 | + GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' ); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Output the select to change the entry creator |
|
| 197 | - * @param int $form_id GF Form ID |
|
| 198 | - * @param array $entry GF entry array |
|
| 199 | - * @return void |
|
| 200 | - */ |
|
| 201 | - function add_select($form_id, $entry ) { |
|
| 195 | + /** |
|
| 196 | + * Output the select to change the entry creator |
|
| 197 | + * @param int $form_id GF Form ID |
|
| 198 | + * @param array $entry GF entry array |
|
| 199 | + * @return void |
|
| 200 | + */ |
|
| 201 | + function add_select($form_id, $entry ) { |
|
| 202 | 202 | |
| 203 | - if( rgpost('screen_mode') !== 'edit' ) { |
|
| 204 | - return; |
|
| 205 | - } |
|
| 203 | + if( rgpost('screen_mode') !== 'edit' ) { |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $users = GVCommon::get_users( 'change_entry_creator' ); |
|
| 207 | + $users = GVCommon::get_users( 'change_entry_creator' ); |
|
| 208 | 208 | |
| 209 | - $output = '<label for="change_created_by">'; |
|
| 210 | - $output .= esc_html__('Change Entry Creator:', 'gravityview'); |
|
| 211 | - $output .= '</label> |
|
| 209 | + $output = '<label for="change_created_by">'; |
|
| 210 | + $output .= esc_html__('Change Entry Creator:', 'gravityview'); |
|
| 211 | + $output .= '</label> |
|
| 212 | 212 | <select name="created_by" id="change_created_by" class="widefat">'; |
| 213 | - $output .= '<option value=""> — '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' — </option>'; |
|
| 214 | - foreach($users as $user) { |
|
| 215 | - $output .= '<option value="'. $user->ID .'"'. selected( $entry['created_by'], $user->ID, false ).'>'.esc_attr( $user->display_name.' ('.$user->user_nicename.')' ).'</option>'; |
|
| 216 | - } |
|
| 217 | - $output .= '</select>'; |
|
| 218 | - $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />'; |
|
| 219 | - echo $output; |
|
| 220 | - |
|
| 221 | - } |
|
| 213 | + $output .= '<option value=""> — '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' — </option>'; |
|
| 214 | + foreach($users as $user) { |
|
| 215 | + $output .= '<option value="'. $user->ID .'"'. selected( $entry['created_by'], $user->ID, false ).'>'.esc_attr( $user->display_name.' ('.$user->user_nicename.')' ).'</option>'; |
|
| 216 | + } |
|
| 217 | + $output .= '</select>'; |
|
| 218 | + $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />'; |
|
| 219 | + echo $output; |
|
| 220 | + |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -10,17 +10,17 @@ discard block |
||
| 10 | 10 | /** |
| 11 | 11 | * @since 1.5.1 |
| 12 | 12 | */ |
| 13 | - add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 ); |
|
| 13 | + add_action( 'gform_user_registered', array( $this, 'assign_new_user_to_lead' ), 10, 4 ); |
|
| 14 | 14 | |
| 15 | 15 | // ONLY ADMIN FROM HERE ON. |
| 16 | - if( !is_admin() ) { return; } |
|
| 16 | + if ( ! is_admin() ) { return; } |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality |
| 20 | 20 | * @since 1.7.4 |
| 21 | 21 | * @param boolean $disable Disable the Change Entry Creator functionality. Default: false. |
| 22 | 22 | */ |
| 23 | - if( apply_filters('gravityview_disable_change_entry_creator', false ) ) { |
|
| 23 | + if ( apply_filters( 'gravityview_disable_change_entry_creator', false ) ) { |
|
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | * Use `init` to fix bbPress warning |
| 29 | 29 | * @see https://bbpress.trac.wordpress.org/ticket/2309 |
| 30 | 30 | */ |
| 31 | - add_action('init', array( $this, 'load'), 100 ); |
|
| 31 | + add_action( 'init', array( $this, 'load' ), 100 ); |
|
| 32 | 32 | |
| 33 | - add_action('plugins_loaded', array( $this, 'prevent_conflicts') ); |
|
| 33 | + add_action( 'plugins_loaded', array( $this, 'prevent_conflicts' ) ); |
|
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
@@ -56,24 +56,24 @@ discard block |
||
| 56 | 56 | $assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry ); |
| 57 | 57 | |
| 58 | 58 | // If filter returns false, do not process |
| 59 | - if( empty( $assign_to_lead ) ) { |
|
| 59 | + if ( empty( $assign_to_lead ) ) { |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing |
| 64 | - $result = RGFormsModel::update_lead_property( $entry['id'], 'created_by', $user_id, false, true ); |
|
| 64 | + $result = RGFormsModel::update_lead_property( $entry[ 'id' ], 'created_by', $user_id, false, true ); |
|
| 65 | 65 | |
| 66 | - if( empty( $result ) ) { |
|
| 67 | - $status = __('Error', 'gravityview'); |
|
| 66 | + if ( empty( $result ) ) { |
|
| 67 | + $status = __( 'Error', 'gravityview' ); |
|
| 68 | 68 | } else { |
| 69 | - $status = __('Success', 'gravityview'); |
|
| 69 | + $status = __( 'Success', 'gravityview' ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id ); |
|
| 72 | + $note = sprintf( _x( '%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview' ), $status, $user_id ); |
|
| 73 | 73 | |
| 74 | - do_action( 'gravityview_log_debug', 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - '.$note ); |
|
| 74 | + do_action( 'gravityview_log_debug', 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - ' . $note ); |
|
| 75 | 75 | |
| 76 | - GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' ); |
|
| 76 | + GravityView_Entry_Notes::add_note( $entry[ 'id' ], -1, 'GravityView', $note, 'gravityview' ); |
|
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | |
@@ -85,20 +85,20 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | // Plugin that was provided here: |
| 87 | 87 | // @link https://gravityview.co/support/documentation/201991205/ |
| 88 | - remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 ); |
|
| 89 | - remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 ); |
|
| 88 | + remove_action( "gform_entry_info", 'gravityview_change_entry_creator_form', 10 ); |
|
| 89 | + remove_action( "gform_after_update_entry", 'gravityview_update_entry_creator', 10 ); |
|
| 90 | 90 | |
| 91 | 91 | // Disable for Gravity Forms Add-ons 3.6.2 and lower |
| 92 | - if( class_exists( 'KWS_GF_Change_Lead_Creator' ) ) { |
|
| 92 | + if ( class_exists( 'KWS_GF_Change_Lead_Creator' ) ) { |
|
| 93 | 93 | |
| 94 | 94 | $Old_Lead_Creator = new KWS_GF_Change_Lead_Creator; |
| 95 | 95 | |
| 96 | 96 | // Now, no validation is required in the methods; let's hook in. |
| 97 | - remove_action('admin_init', array( $Old_Lead_Creator, 'set_screen_mode' ) ); |
|
| 97 | + remove_action( 'admin_init', array( $Old_Lead_Creator, 'set_screen_mode' ) ); |
|
| 98 | 98 | |
| 99 | - remove_action("gform_entry_info", array( $Old_Lead_Creator, 'add_select' ), 10 ); |
|
| 99 | + remove_action( "gform_entry_info", array( $Old_Lead_Creator, 'add_select' ), 10 ); |
|
| 100 | 100 | |
| 101 | - remove_action("gform_after_update_entry", array( $Old_Lead_Creator, 'update_entry_creator' ), 10 ); |
|
| 101 | + remove_action( "gform_after_update_entry", array( $Old_Lead_Creator, 'update_entry_creator' ), 10 ); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | } |
@@ -110,26 +110,26 @@ discard block |
||
| 110 | 110 | function load() { |
| 111 | 111 | |
| 112 | 112 | // Does GF exist? |
| 113 | - if( !class_exists('GFCommon') ) { |
|
| 113 | + if ( ! class_exists( 'GFCommon' ) ) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // Can the user edit entries? |
| 118 | - if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) { |
|
| 118 | + if ( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) { |
|
| 119 | 119 | return; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // If screen mode isn't set, then we're in the wrong place. |
| 123 | - if( empty( $_REQUEST['screen_mode'] ) ) { |
|
| 123 | + if ( empty( $_REQUEST[ 'screen_mode' ] ) ) { |
|
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Now, no validation is required in the methods; let's hook in. |
| 128 | - add_action('admin_init', array( &$this, 'set_screen_mode' ) ); |
|
| 128 | + add_action( 'admin_init', array( &$this, 'set_screen_mode' ) ); |
|
| 129 | 129 | |
| 130 | - add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2); |
|
| 130 | + add_action( "gform_entry_info", array( &$this, 'add_select' ), 10, 2 ); |
|
| 131 | 131 | |
| 132 | - add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2); |
|
| 132 | + add_action( "gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2 ); |
|
| 133 | 133 | |
| 134 | 134 | } |
| 135 | 135 | |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | function set_screen_mode() { |
| 141 | 141 | |
| 142 | 142 | // If $_GET['screen_mode'] is set to edit, set $_POST value |
| 143 | - if( rgget('screen_mode') === 'edit' ) { |
|
| 144 | - $_POST["screen_mode"] = 'edit'; |
|
| 143 | + if ( rgget( 'screen_mode' ) === 'edit' ) { |
|
| 144 | + $_POST[ "screen_mode" ] = 'edit'; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | } |
@@ -152,42 +152,42 @@ discard block |
||
| 152 | 152 | * @param int $entry_id Entry ID |
| 153 | 153 | * @return void |
| 154 | 154 | */ |
| 155 | - function update_entry_creator($form, $entry_id) { |
|
| 155 | + function update_entry_creator( $form, $entry_id ) { |
|
| 156 | 156 | global $current_user; |
| 157 | 157 | |
| 158 | 158 | // Update the entry |
| 159 | - $created_by = absint( rgpost('created_by') ); |
|
| 159 | + $created_by = absint( rgpost( 'created_by' ) ); |
|
| 160 | 160 | |
| 161 | 161 | RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by ); |
| 162 | 162 | |
| 163 | 163 | // If the creator has changed, let's add a note about who it used to be. |
| 164 | - $originally_created_by = rgpost('originally_created_by'); |
|
| 164 | + $originally_created_by = rgpost( 'originally_created_by' ); |
|
| 165 | 165 | |
| 166 | 166 | // If there's no owner and there didn't used to be, keep going |
| 167 | - if( empty( $originally_created_by ) && empty( $created_by ) ) { |
|
| 167 | + if ( empty( $originally_created_by ) && empty( $created_by ) ) { |
|
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // If the values have changed |
| 172 | - if( absint( $originally_created_by ) !== absint( $created_by ) ) { |
|
| 172 | + if ( absint( $originally_created_by ) !== absint( $created_by ) ) { |
|
| 173 | 173 | |
| 174 | - $user_data = get_userdata($current_user->ID); |
|
| 174 | + $user_data = get_userdata( $current_user->ID ); |
|
| 175 | 175 | |
| 176 | - $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview'); |
|
| 176 | + $user_format = _x( '%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview' ); |
|
| 177 | 177 | |
| 178 | - $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview'); |
|
| 178 | + $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview' ); |
|
| 179 | 179 | |
| 180 | - if( !empty( $originally_created_by ) ) { |
|
| 181 | - $originally_created_by_user_data = get_userdata($originally_created_by); |
|
| 180 | + if ( ! empty( $originally_created_by ) ) { |
|
| 181 | + $originally_created_by_user_data = get_userdata( $originally_created_by ); |
|
| 182 | 182 | $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID ); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if( !empty( $created_by ) ) { |
|
| 186 | - $created_by_user_data = get_userdata($created_by); |
|
| 185 | + if ( ! empty( $created_by ) ) { |
|
| 186 | + $created_by_user_data = get_userdata( $created_by ); |
|
| 187 | 187 | $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID ); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' ); |
|
| 190 | + GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __( 'Changed entry creator from %s to %s', 'gravityview' ), $original_name, $created_by_name ), 'note' ); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | } |
@@ -198,24 +198,24 @@ discard block |
||
| 198 | 198 | * @param array $entry GF entry array |
| 199 | 199 | * @return void |
| 200 | 200 | */ |
| 201 | - function add_select($form_id, $entry ) { |
|
| 201 | + function add_select( $form_id, $entry ) { |
|
| 202 | 202 | |
| 203 | - if( rgpost('screen_mode') !== 'edit' ) { |
|
| 203 | + if ( rgpost( 'screen_mode' ) !== 'edit' ) { |
|
| 204 | 204 | return; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | $users = GVCommon::get_users( 'change_entry_creator' ); |
| 208 | 208 | |
| 209 | 209 | $output = '<label for="change_created_by">'; |
| 210 | - $output .= esc_html__('Change Entry Creator:', 'gravityview'); |
|
| 210 | + $output .= esc_html__( 'Change Entry Creator:', 'gravityview' ); |
|
| 211 | 211 | $output .= '</label> |
| 212 | 212 | <select name="created_by" id="change_created_by" class="widefat">'; |
| 213 | - $output .= '<option value=""> — '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' — </option>'; |
|
| 214 | - foreach($users as $user) { |
|
| 215 | - $output .= '<option value="'. $user->ID .'"'. selected( $entry['created_by'], $user->ID, false ).'>'.esc_attr( $user->display_name.' ('.$user->user_nicename.')' ).'</option>'; |
|
| 213 | + $output .= '<option value=""> — ' . esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview' ) . ' — </option>'; |
|
| 214 | + foreach ( $users as $user ) { |
|
| 215 | + $output .= '<option value="' . $user->ID . '"' . selected( $entry[ 'created_by' ], $user->ID, false ) . '>' . esc_attr( $user->display_name . ' (' . $user->user_nicename . ')' ) . '</option>'; |
|
| 216 | 216 | } |
| 217 | 217 | $output .= '</select>'; |
| 218 | - $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />'; |
|
| 218 | + $output .= '<input name="originally_created_by" value="' . esc_attr( $entry[ 'created_by' ] ) . '" type="hidden" />'; |
|
| 219 | 219 | echo $output; |
| 220 | 220 | |
| 221 | 221 | } |
@@ -245,12 +245,12 @@ discard block |
||
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
| 248 | - * @hack |
|
| 249 | - * In case of email/email confirmation, the input for email has the same id as the parent field |
|
| 250 | - */ |
|
| 248 | + * @hack |
|
| 249 | + * In case of email/email confirmation, the input for email has the same id as the parent field |
|
| 250 | + */ |
|
| 251 | 251 | if( 'email' === $field->type && false === strpos( $input['id'], '.' ) ) { |
| 252 | - continue; |
|
| 253 | - } |
|
| 252 | + continue; |
|
| 253 | + } |
|
| 254 | 254 | $fields["{$input['id']}"] = array( |
| 255 | 255 | 'label' => rgar( $input, 'label' ), |
| 256 | 256 | 'customLabel' => rgar( $input, 'customLabel' ), |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | } elseif ( 'delete' === RGForms::get( 'action' ) ) { |
| 428 | 428 | $criteria['context_view_id'] = isset( $_GET['view_id'] ) ? intval( $_GET['view_id'] ) : null; |
| 429 | 429 | } elseif( !isset( $criteria['context_view_id'] ) ) { |
| 430 | - // Prevent overriding the Context View ID: Some widgets could set the context_view_id (e.g. Recent Entries widget) |
|
| 430 | + // Prevent overriding the Context View ID: Some widgets could set the context_view_id (e.g. Recent Entries widget) |
|
| 431 | 431 | $criteria['context_view_id'] = null; |
| 432 | 432 | } |
| 433 | 433 | |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | ), |
| 1163 | 1163 | ); |
| 1164 | 1164 | |
| 1165 | - $fields = $date_created + $fields; |
|
| 1165 | + $fields = $date_created + $fields; |
|
| 1166 | 1166 | |
| 1167 | 1167 | $blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', $blacklist, NULL ); |
| 1168 | 1168 | |
@@ -1174,13 +1174,13 @@ discard block |
||
| 1174 | 1174 | } |
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | - /** |
|
| 1178 | - * @filter `gravityview/common/sortable_fields` Filter the sortable fields |
|
| 1179 | - * @since 1.12 |
|
| 1180 | - * @param array $fields Sub-set of GF form fields that are sortable |
|
| 1181 | - * @param int $formid The Gravity Forms form ID that the fields are from |
|
| 1182 | - */ |
|
| 1183 | - $fields = apply_filters( 'gravityview/common/sortable_fields', $fields, $formid ); |
|
| 1177 | + /** |
|
| 1178 | + * @filter `gravityview/common/sortable_fields` Filter the sortable fields |
|
| 1179 | + * @since 1.12 |
|
| 1180 | + * @param array $fields Sub-set of GF form fields that are sortable |
|
| 1181 | + * @param int $formid The Gravity Forms form ID that the fields are from |
|
| 1182 | + */ |
|
| 1183 | + $fields = apply_filters( 'gravityview/common/sortable_fields', $fields, $formid ); |
|
| 1184 | 1184 | |
| 1185 | 1185 | return $fields; |
| 1186 | 1186 | } |
@@ -1472,17 +1472,17 @@ discard block |
||
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | 1474 | |
| 1475 | - /** |
|
| 1476 | - * Display updated/error notice |
|
| 1477 | - * |
|
| 1478 | - * @param string $notice text/HTML of notice |
|
| 1479 | - * @param string $class CSS class for notice (`updated` or `error`) |
|
| 1480 | - * |
|
| 1481 | - * @return string |
|
| 1482 | - */ |
|
| 1483 | - public static function generate_notice( $notice, $class = '' ) { |
|
| 1484 | - return '<div class="gv-notice '.gravityview_sanitize_html_class( $class ) .'">'. $notice .'</div>'; |
|
| 1485 | - } |
|
| 1475 | + /** |
|
| 1476 | + * Display updated/error notice |
|
| 1477 | + * |
|
| 1478 | + * @param string $notice text/HTML of notice |
|
| 1479 | + * @param string $class CSS class for notice (`updated` or `error`) |
|
| 1480 | + * |
|
| 1481 | + * @return string |
|
| 1482 | + */ |
|
| 1483 | + public static function generate_notice( $notice, $class = '' ) { |
|
| 1484 | + return '<div class="gv-notice '.gravityview_sanitize_html_class( $class ) .'">'. $notice .'</div>'; |
|
| 1485 | + } |
|
| 1486 | 1486 | |
| 1487 | 1487 | /** |
| 1488 | 1488 | * Inspired on \GFCommon::encode_shortcodes, reverse the encoding by replacing the ascii characters by the shortcode brackets |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | $entry = self::get_entry( $entry_slug, true ); |
| 126 | 126 | |
| 127 | - $form = self::get_form( $entry['form_id'] ); |
|
| 127 | + $form = self::get_form( $entry[ 'form_id' ] ); |
|
| 128 | 128 | |
| 129 | 129 | return $form; |
| 130 | 130 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | $results = GFAPI::get_entries( intval( $form_id ), $search_criteria, null, $paging ); |
| 184 | 184 | |
| 185 | - $result = ( ! empty( $results ) && ! empty( $results[0]['id'] ) ) ? $results[0]['id'] : null; |
|
| 185 | + $result = ( ! empty( $results ) && ! empty( $results[ 0 ][ 'id' ] ) ) ? $results[ 0 ][ 'id' ] : null; |
|
| 186 | 186 | |
| 187 | 187 | return $result; |
| 188 | 188 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * |
| 198 | 198 | * @return array Empty array if GFAPI class isn't available or no forms. Otherwise, the array of Forms |
| 199 | 199 | */ |
| 200 | - public static function get_forms( $active = true, $trash = false ) { |
|
| 200 | + public static function get_forms( $active = true, $trash = false ) { |
|
| 201 | 201 | $forms = array(); |
| 202 | 202 | if ( class_exists( 'GFAPI' ) ) { |
| 203 | 203 | $forms = GFAPI::get_forms( $active, $trash ); |
@@ -225,9 +225,9 @@ discard block |
||
| 225 | 225 | $has_post_fields = false; |
| 226 | 226 | |
| 227 | 227 | if ( $form ) { |
| 228 | - foreach ( $form['fields'] as $field ) { |
|
| 229 | - if ( $include_parent_field || empty( $field['inputs'] ) ) { |
|
| 230 | - $fields["{$field['id']}"] = array( |
|
| 228 | + foreach ( $form[ 'fields' ] as $field ) { |
|
| 229 | + if ( $include_parent_field || empty( $field[ 'inputs' ] ) ) { |
|
| 230 | + $fields[ "{$field[ 'id' ]}" ] = array( |
|
| 231 | 231 | 'label' => rgar( $field, 'label' ), |
| 232 | 232 | 'parent' => null, |
| 233 | 233 | 'type' => rgar( $field, 'type' ), |
@@ -236,10 +236,10 @@ discard block |
||
| 236 | 236 | ); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - if ( $add_default_properties && ! empty( $field['inputs'] ) ) { |
|
| 240 | - foreach ( $field['inputs'] as $input ) { |
|
| 239 | + if ( $add_default_properties && ! empty( $field[ 'inputs' ] ) ) { |
|
| 240 | + foreach ( $field[ 'inputs' ] as $input ) { |
|
| 241 | 241 | |
| 242 | - if( ! empty( $input['isHidden'] ) ) { |
|
| 242 | + if ( ! empty( $input[ 'isHidden' ] ) ) { |
|
| 243 | 243 | continue; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | * @hack |
| 248 | 248 | * In case of email/email confirmation, the input for email has the same id as the parent field |
| 249 | 249 | */ |
| 250 | - if( 'email' === $field['type'] && false === strpos( $input['id'], '.' ) ) { |
|
| 250 | + if ( 'email' === $field[ 'type' ] && false === strpos( $input[ 'id' ], '.' ) ) { |
|
| 251 | 251 | continue; |
| 252 | 252 | } |
| 253 | - $fields["{$input['id']}"] = array( |
|
| 253 | + $fields[ "{$input[ 'id' ]}" ] = array( |
|
| 254 | 254 | 'label' => rgar( $input, 'label' ), |
| 255 | 255 | 'customLabel' => rgar( $input, 'customLabel' ), |
| 256 | 256 | 'parent' => $field, |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | |
| 265 | - if( GFCommon::is_product_field( $field['type'] ) ){ |
|
| 265 | + if ( GFCommon::is_product_field( $field[ 'type' ] ) ) { |
|
| 266 | 266 | $has_product_fields = true; |
| 267 | 267 | } |
| 268 | 268 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * @since 1.7 |
| 277 | 277 | */ |
| 278 | 278 | if ( $has_post_fields ) { |
| 279 | - $fields['post_id'] = array( |
|
| 279 | + $fields[ 'post_id' ] = array( |
|
| 280 | 280 | 'label' => __( 'Post ID', 'gravityview' ), |
| 281 | 281 | 'type' => 'post_id', |
| 282 | 282 | ); |
@@ -287,10 +287,10 @@ discard block |
||
| 287 | 287 | $payment_fields = GravityView_Fields::get_all( 'pricing' ); |
| 288 | 288 | |
| 289 | 289 | foreach ( $payment_fields as $payment_field ) { |
| 290 | - if( isset( $fields["{$payment_field->name}"] ) ) { |
|
| 290 | + if ( isset( $fields[ "{$payment_field->name}" ] ) ) { |
|
| 291 | 291 | continue; |
| 292 | 292 | } |
| 293 | - $fields["{$payment_field->name}"] = array( |
|
| 293 | + $fields[ "{$payment_field->name}" ] = array( |
|
| 294 | 294 | 'label' => $payment_field->label, |
| 295 | 295 | 'desc' => $payment_field->description, |
| 296 | 296 | 'type' => $payment_field->name, |
@@ -322,9 +322,9 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | $fields = array(); |
| 324 | 324 | |
| 325 | - foreach ( $extra_fields as $key => $field ){ |
|
| 326 | - if ( ! empty( $only_default_column ) && ! empty( $field['is_default_column'] ) ) { |
|
| 327 | - $fields[ $key ] = array( 'label' => $field['label'], 'type' => 'entry_meta' ); |
|
| 325 | + foreach ( $extra_fields as $key => $field ) { |
|
| 326 | + if ( ! empty( $only_default_column ) && ! empty( $field[ 'is_default_column' ] ) ) { |
|
| 327 | + $fields[ $key ] = array( 'label' => $field[ 'label' ], 'type' => 'entry_meta' ); |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
@@ -364,32 +364,32 @@ discard block |
||
| 364 | 364 | 'search_criteria' => null, |
| 365 | 365 | 'sorting' => null, |
| 366 | 366 | 'paging' => null, |
| 367 | - 'cache' => (isset( $passed_criteria['cache'] ) ? $passed_criteria['cache'] : true), |
|
| 367 | + 'cache' => ( isset( $passed_criteria[ 'cache' ] ) ? $passed_criteria[ 'cache' ] : true ), |
|
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | 370 | $criteria = wp_parse_args( $passed_criteria, $search_criteria_defaults ); |
| 371 | 371 | |
| 372 | - if ( ! empty( $criteria['search_criteria']['field_filters'] ) ) { |
|
| 373 | - foreach ( $criteria['search_criteria']['field_filters'] as &$filter ) { |
|
| 372 | + if ( ! empty( $criteria[ 'search_criteria' ][ 'field_filters' ] ) ) { |
|
| 373 | + foreach ( $criteria[ 'search_criteria' ][ 'field_filters' ] as &$filter ) { |
|
| 374 | 374 | |
| 375 | 375 | if ( ! is_array( $filter ) ) { |
| 376 | 376 | continue; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | // By default, we want searches to be wildcard for each field. |
| 380 | - $filter['operator'] = empty( $filter['operator'] ) ? 'contains' : $filter['operator']; |
|
| 380 | + $filter[ 'operator' ] = empty( $filter[ 'operator' ] ) ? 'contains' : $filter[ 'operator' ]; |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * @filter `gravityview_search_operator` Modify the search operator for the field (contains, is, isnot, etc) |
| 384 | 384 | * @param string $operator Existing search operator |
| 385 | 385 | * @param array $filter array with `key`, `value`, `operator`, `type` keys |
| 386 | 386 | */ |
| 387 | - $filter['operator'] = apply_filters( 'gravityview_search_operator', $filter['operator'], $filter ); |
|
| 387 | + $filter[ 'operator' ] = apply_filters( 'gravityview_search_operator', $filter[ 'operator' ], $filter ); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // don't send just the [mode] without any field filter. |
| 391 | - if( count( $criteria['search_criteria']['field_filters'] ) === 1 && array_key_exists( 'mode' , $criteria['search_criteria']['field_filters'] ) ) { |
|
| 392 | - unset( $criteria['search_criteria']['field_filters']['mode'] ); |
|
| 391 | + if ( count( $criteria[ 'search_criteria' ][ 'field_filters' ] ) === 1 && array_key_exists( 'mode', $criteria[ 'search_criteria' ][ 'field_filters' ] ) ) { |
|
| 392 | + unset( $criteria[ 'search_criteria' ][ 'field_filters' ][ 'mode' ] ); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | } |
@@ -400,21 +400,21 @@ discard block |
||
| 400 | 400 | * Prepare date formats to be in Gravity Forms DB format; |
| 401 | 401 | * $passed_criteria may include date formats incompatible with Gravity Forms. |
| 402 | 402 | */ |
| 403 | - foreach ( array('start_date', 'end_date' ) as $key ) { |
|
| 403 | + foreach ( array( 'start_date', 'end_date' ) as $key ) { |
|
| 404 | 404 | |
| 405 | - if ( ! empty( $criteria['search_criteria'][ $key ] ) ) { |
|
| 405 | + if ( ! empty( $criteria[ 'search_criteria' ][ $key ] ) ) { |
|
| 406 | 406 | |
| 407 | 407 | // Use date_create instead of new DateTime so it returns false if invalid date format. |
| 408 | - $date = date_create( $criteria['search_criteria'][ $key ] ); |
|
| 408 | + $date = date_create( $criteria[ 'search_criteria' ][ $key ] ); |
|
| 409 | 409 | |
| 410 | 410 | if ( $date ) { |
| 411 | 411 | // Gravity Forms wants dates in the `Y-m-d H:i:s` format. |
| 412 | - $criteria['search_criteria'][ $key ] = $date->format( 'Y-m-d H:i:s' ); |
|
| 412 | + $criteria[ 'search_criteria' ][ $key ] = $date->format( 'Y-m-d H:i:s' ); |
|
| 413 | 413 | } else { |
| 414 | 414 | // If it's an invalid date, unset it. Gravity Forms freaks out otherwise. |
| 415 | - unset( $criteria['search_criteria'][ $key ] ); |
|
| 415 | + unset( $criteria[ 'search_criteria' ][ $key ] ); |
|
| 416 | 416 | |
| 417 | - do_action( 'gravityview_log_error', '[filter_get_entries_criteria] '.$key.' Date format not valid:', $criteria['search_criteria'][ $key ] ); |
|
| 417 | + do_action( 'gravityview_log_error', '[filter_get_entries_criteria] ' . $key . ' Date format not valid:', $criteria[ 'search_criteria' ][ $key ] ); |
|
| 418 | 418 | } |
| 419 | 419 | } |
| 420 | 420 | } |
@@ -422,12 +422,12 @@ discard block |
||
| 422 | 422 | |
| 423 | 423 | // When multiple views are embedded, OR single entry, calculate the context view id and send it to the advanced filter |
| 424 | 424 | if ( class_exists( 'GravityView_View_Data' ) && GravityView_View_Data::getInstance()->has_multiple_views() || GravityView_frontend::getInstance()->getSingleEntry() ) { |
| 425 | - $criteria['context_view_id'] = GravityView_frontend::getInstance()->get_context_view_id(); |
|
| 425 | + $criteria[ 'context_view_id' ] = GravityView_frontend::getInstance()->get_context_view_id(); |
|
| 426 | 426 | } elseif ( 'delete' === RGForms::get( 'action' ) ) { |
| 427 | - $criteria['context_view_id'] = isset( $_GET['view_id'] ) ? intval( $_GET['view_id'] ) : null; |
|
| 428 | - } elseif( !isset( $criteria['context_view_id'] ) ) { |
|
| 427 | + $criteria[ 'context_view_id' ] = isset( $_GET[ 'view_id' ] ) ? intval( $_GET[ 'view_id' ] ) : null; |
|
| 428 | + } elseif ( ! isset( $criteria[ 'context_view_id' ] ) ) { |
|
| 429 | 429 | // Prevent overriding the Context View ID: Some widgets could set the context_view_id (e.g. Recent Entries widget) |
| 430 | - $criteria['context_view_id'] = null; |
|
| 430 | + $criteria[ 'context_view_id' ] = null; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | * @param array $form_ids Forms to search |
| 437 | 437 | * @param int $view_id ID of the view being used to search |
| 438 | 438 | */ |
| 439 | - $criteria = apply_filters( 'gravityview_search_criteria', $criteria, $form_ids, $criteria['context_view_id'] ); |
|
| 439 | + $criteria = apply_filters( 'gravityview_search_criteria', $criteria, $form_ids, $criteria[ 'context_view_id' ] ); |
|
| 440 | 440 | |
| 441 | 441 | return (array)$criteria; |
| 442 | 442 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | /** Reduce # of database calls */ |
| 468 | 468 | add_filter( 'gform_is_encrypted_field', '__return_false' ); |
| 469 | 469 | |
| 470 | - if ( ! empty( $criteria['cache'] ) ) { |
|
| 470 | + if ( ! empty( $criteria[ 'cache' ] ) ) { |
|
| 471 | 471 | |
| 472 | 472 | $Cache = new GravityView_Cache( $form_ids, $criteria ); |
| 473 | 473 | |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | // Still update the total count when using cached results |
| 477 | 477 | if ( ! is_null( $total ) ) { |
| 478 | - $total = GFAPI::count_entries( $form_ids, $criteria['search_criteria'] ); |
|
| 478 | + $total = GFAPI::count_entries( $form_ids, $criteria[ 'search_criteria' ] ); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | $return = $entries; |
@@ -495,9 +495,9 @@ discard block |
||
| 495 | 495 | $entries = apply_filters( 'gravityview_before_get_entries', null, $criteria, $passed_criteria, $total ); |
| 496 | 496 | |
| 497 | 497 | // No entries returned from gravityview_before_get_entries |
| 498 | - if( is_null( $entries ) ) { |
|
| 498 | + if ( is_null( $entries ) ) { |
|
| 499 | 499 | |
| 500 | - $entries = GFAPI::get_entries( $form_ids, $criteria['search_criteria'], $criteria['sorting'], $criteria['paging'], $total ); |
|
| 500 | + $entries = GFAPI::get_entries( $form_ids, $criteria[ 'search_criteria' ], $criteria[ 'sorting' ], $criteria[ 'paging' ], $total ); |
|
| 501 | 501 | |
| 502 | 502 | if ( is_wp_error( $entries ) ) { |
| 503 | 503 | do_action( 'gravityview_log_error', $entries->get_error_message(), $entries ); |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - if ( ! empty( $criteria['cache'] ) && isset( $Cache ) ) { |
|
| 509 | + if ( ! empty( $criteria[ 'cache' ] ) && isset( $Cache ) ) { |
|
| 510 | 510 | |
| 511 | 511 | // Cache results |
| 512 | 512 | $Cache->set( $entries, 'entries' ); |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | */ |
| 594 | 594 | $check_entry_display = apply_filters( 'gravityview/common/get_entry/check_entry_display', $check_entry_display, $entry ); |
| 595 | 595 | |
| 596 | - if( $check_entry_display ) { |
|
| 596 | + if ( $check_entry_display ) { |
|
| 597 | 597 | // Is the entry allowed |
| 598 | 598 | $entry = self::check_entry_display( $entry ); |
| 599 | 599 | } |
@@ -626,12 +626,12 @@ discard block |
||
| 626 | 626 | |
| 627 | 627 | $value = false; |
| 628 | 628 | |
| 629 | - if( 'context' === $val1 ) { |
|
| 629 | + if ( 'context' === $val1 ) { |
|
| 630 | 630 | |
| 631 | 631 | $matching_contexts = array( $val2 ); |
| 632 | 632 | |
| 633 | 633 | // We allow for non-standard contexts. |
| 634 | - switch( $val2 ) { |
|
| 634 | + switch ( $val2 ) { |
|
| 635 | 635 | // Check for either single or edit |
| 636 | 636 | case 'singular': |
| 637 | 637 | $matching_contexts = array( 'single', 'edit' ); |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | return false; |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - if ( empty( $entry['form_id'] ) ) { |
|
| 694 | + if ( empty( $entry[ 'form_id' ] ) ) { |
|
| 695 | 695 | do_action( 'gravityview_log_debug', '[apply_filters_to_entry] Entry is empty! Entry:', $entry ); |
| 696 | 696 | return false; |
| 697 | 697 | } |
@@ -699,26 +699,26 @@ discard block |
||
| 699 | 699 | $criteria = self::calculate_get_entries_criteria(); |
| 700 | 700 | |
| 701 | 701 | // Make sure the current View is connected to the same form as the Entry |
| 702 | - if( ! empty( $criteria['context_view_id'] ) ) { |
|
| 703 | - $context_view_id = intval( $criteria['context_view_id'] ); |
|
| 702 | + if ( ! empty( $criteria[ 'context_view_id' ] ) ) { |
|
| 703 | + $context_view_id = intval( $criteria[ 'context_view_id' ] ); |
|
| 704 | 704 | $context_form_id = gravityview_get_form_id( $context_view_id ); |
| 705 | - if( intval( $context_form_id ) !== intval( $entry['form_id'] ) ) { |
|
| 706 | - do_action( 'gravityview_log_debug', sprintf( '[apply_filters_to_entry] Entry form ID does not match current View connected form ID:', $entry['form_id'] ), $criteria['context_view_id'] ); |
|
| 705 | + if ( intval( $context_form_id ) !== intval( $entry[ 'form_id' ] ) ) { |
|
| 706 | + do_action( 'gravityview_log_debug', sprintf( '[apply_filters_to_entry] Entry form ID does not match current View connected form ID:', $entry[ 'form_id' ] ), $criteria[ 'context_view_id' ] ); |
|
| 707 | 707 | return false; |
| 708 | 708 | } |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | - if ( empty( $criteria['search_criteria'] ) || ! is_array( $criteria['search_criteria'] ) ) { |
|
| 711 | + if ( empty( $criteria[ 'search_criteria' ] ) || ! is_array( $criteria[ 'search_criteria' ] ) ) { |
|
| 712 | 712 | do_action( 'gravityview_log_debug', '[apply_filters_to_entry] Entry approved! No search criteria found:', $criteria ); |
| 713 | 713 | return $entry; |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - $search_criteria = $criteria['search_criteria']; |
|
| 716 | + $search_criteria = $criteria[ 'search_criteria' ]; |
|
| 717 | 717 | unset( $criteria ); |
| 718 | 718 | |
| 719 | 719 | // check entry status |
| 720 | - if ( array_key_exists( 'status', $search_criteria ) && $search_criteria['status'] != $entry['status'] ) { |
|
| 721 | - do_action( 'gravityview_log_debug', sprintf( '[apply_filters_to_entry] Entry status - %s - is not valid according to filter:', $entry['status'] ), $search_criteria ); |
|
| 720 | + if ( array_key_exists( 'status', $search_criteria ) && $search_criteria[ 'status' ] != $entry[ 'status' ] ) { |
|
| 721 | + do_action( 'gravityview_log_debug', sprintf( '[apply_filters_to_entry] Entry status - %s - is not valid according to filter:', $entry[ 'status' ] ), $search_criteria ); |
|
| 722 | 722 | return false; |
| 723 | 723 | } |
| 724 | 724 | |
@@ -726,37 +726,37 @@ discard block |
||
| 726 | 726 | // @todo: Does it make sense to apply the Date create filters to the single entry? |
| 727 | 727 | |
| 728 | 728 | // field_filters |
| 729 | - if ( empty( $search_criteria['field_filters'] ) || ! is_array( $search_criteria['field_filters'] ) ) { |
|
| 729 | + if ( empty( $search_criteria[ 'field_filters' ] ) || ! is_array( $search_criteria[ 'field_filters' ] ) ) { |
|
| 730 | 730 | do_action( 'gravityview_log_debug', '[apply_filters_to_entry] Entry approved! No field filters criteria found:', $search_criteria ); |
| 731 | 731 | return $entry; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - $filters = $search_criteria['field_filters']; |
|
| 734 | + $filters = $search_criteria[ 'field_filters' ]; |
|
| 735 | 735 | unset( $search_criteria ); |
| 736 | 736 | |
| 737 | - $mode = array_key_exists( 'mode', $filters ) ? strtolower( $filters['mode'] ) : 'all'; |
|
| 738 | - unset( $filters['mode'] ); |
|
| 737 | + $mode = array_key_exists( 'mode', $filters ) ? strtolower( $filters[ 'mode' ] ) : 'all'; |
|
| 738 | + unset( $filters[ 'mode' ] ); |
|
| 739 | 739 | |
| 740 | - $form = self::get_form( $entry['form_id'] ); |
|
| 740 | + $form = self::get_form( $entry[ 'form_id' ] ); |
|
| 741 | 741 | |
| 742 | 742 | foreach ( $filters as $filter ) { |
| 743 | 743 | |
| 744 | - if ( ! isset( $filter['key'] ) ) { |
|
| 744 | + if ( ! isset( $filter[ 'key' ] ) ) { |
|
| 745 | 745 | continue; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - $k = $filter['key']; |
|
| 748 | + $k = $filter[ 'key' ]; |
|
| 749 | 749 | |
| 750 | 750 | if ( in_array( $k, array( 'created_by', 'payment_status' ) ) ) { |
| 751 | 751 | $field_value = $entry[ $k ]; |
| 752 | 752 | $field = null; |
| 753 | 753 | } else { |
| 754 | 754 | $field = self::get_field( $form, $k ); |
| 755 | - $field_value = GFFormsModel::get_lead_field_value( $entry, $field ); |
|
| 755 | + $field_value = GFFormsModel::get_lead_field_value( $entry, $field ); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - $operator = isset( $filter['operator'] ) ? strtolower( $filter['operator'] ) : 'is'; |
|
| 759 | - $is_value_match = GFFormsModel::is_value_match( $field_value, $filter['value'], $operator, $field ); |
|
| 758 | + $operator = isset( $filter[ 'operator' ] ) ? strtolower( $filter[ 'operator' ] ) : 'is'; |
|
| 759 | + $is_value_match = GFFormsModel::is_value_match( $field_value, $filter[ 'value' ], $operator, $field ); |
|
| 760 | 760 | |
| 761 | 761 | // verify if we are already free to go! |
| 762 | 762 | if ( ! $is_value_match && 'all' === $mode ) { |
@@ -814,18 +814,18 @@ discard block |
||
| 814 | 814 | * Gravity Forms code to adjust date to locally-configured Time Zone |
| 815 | 815 | * @see GFCommon::format_date() for original code |
| 816 | 816 | */ |
| 817 | - $date_gmt_time = mysql2date( 'G', $date_string ); |
|
| 817 | + $date_gmt_time = mysql2date( 'G', $date_string ); |
|
| 818 | 818 | $date_local_timestamp = GFCommon::get_local_timestamp( $date_gmt_time ); |
| 819 | 819 | |
| 820 | - $format = rgar( $atts, 'format' ); |
|
| 821 | - $is_human = ! empty( $atts['human'] ); |
|
| 822 | - $is_diff = ! empty( $atts['diff'] ); |
|
| 823 | - $is_raw = ! empty( $atts['raw'] ); |
|
| 824 | - $is_timestamp = ! empty( $atts['timestamp'] ); |
|
| 825 | - $include_time = ! empty( $atts['time'] ); |
|
| 820 | + $format = rgar( $atts, 'format' ); |
|
| 821 | + $is_human = ! empty( $atts[ 'human' ] ); |
|
| 822 | + $is_diff = ! empty( $atts[ 'diff' ] ); |
|
| 823 | + $is_raw = ! empty( $atts[ 'raw' ] ); |
|
| 824 | + $is_timestamp = ! empty( $atts[ 'timestamp' ] ); |
|
| 825 | + $include_time = ! empty( $atts[ 'time' ] ); |
|
| 826 | 826 | |
| 827 | 827 | // If we're using time diff, we want to have a different default format |
| 828 | - if( empty( $format ) ) { |
|
| 828 | + if ( empty( $format ) ) { |
|
| 829 | 829 | /* translators: %s: relative time from now, used for generic date comparisons. "1 day ago", or "20 seconds ago" */ |
| 830 | 830 | $format = $is_diff ? esc_html__( '%s ago', 'gravityview' ) : get_option( 'date_format' ); |
| 831 | 831 | } |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | // If raw was specified, don't modify the stored value |
| 834 | 834 | if ( $is_raw ) { |
| 835 | 835 | $formatted_date = $date_string; |
| 836 | - } elseif( $is_timestamp ) { |
|
| 836 | + } elseif ( $is_timestamp ) { |
|
| 837 | 837 | $formatted_date = $date_local_timestamp; |
| 838 | 838 | } elseif ( $is_diff ) { |
| 839 | 839 | $formatted_date = sprintf( $format, human_time_diff( $date_gmt_time ) ); |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | |
| 868 | 868 | $label = rgar( $field, 'label' ); |
| 869 | 869 | |
| 870 | - if( floor( $field_id ) !== floatval( $field_id ) ) { |
|
| 870 | + if ( floor( $field_id ) !== floatval( $field_id ) ) { |
|
| 871 | 871 | $label = GFFormsModel::get_choice_text( $field, $field_value, $field_id ); |
| 872 | 872 | } |
| 873 | 873 | |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | * @return GF_Field|null Gravity Forms field object, or NULL: Gravity Forms GFFormsModel does not exist or field at $field_id doesn't exist. |
| 889 | 889 | */ |
| 890 | 890 | public static function get_field( $form, $field_id ) { |
| 891 | - if ( class_exists( 'GFFormsModel' ) ){ |
|
| 891 | + if ( class_exists( 'GFFormsModel' ) ) { |
|
| 892 | 892 | return GFFormsModel::get_field( $form, $field_id ); |
| 893 | 893 | } else { |
| 894 | 894 | return null; |
@@ -935,19 +935,19 @@ discard block |
||
| 935 | 935 | $shortcodes = array(); |
| 936 | 936 | |
| 937 | 937 | preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ); |
| 938 | - if ( empty( $matches ) ){ |
|
| 938 | + if ( empty( $matches ) ) { |
|
| 939 | 939 | return false; |
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | foreach ( $matches as $shortcode ) { |
| 943 | - if ( $tag === $shortcode[2] ) { |
|
| 943 | + if ( $tag === $shortcode[ 2 ] ) { |
|
| 944 | 944 | |
| 945 | 945 | // Changed this to $shortcode instead of true so we get the parsed atts. |
| 946 | - $shortcodes[] = $shortcode; |
|
| 946 | + $shortcodes[ ] = $shortcode; |
|
| 947 | 947 | |
| 948 | - } else if ( isset( $shortcode[5] ) && $results = self::has_shortcode_r( $shortcode[5], $tag ) ) { |
|
| 949 | - foreach( $results as $result ) { |
|
| 950 | - $shortcodes[] = $result; |
|
| 948 | + } else if ( isset( $shortcode[ 5 ] ) && $results = self::has_shortcode_r( $shortcode[ 5 ], $tag ) ) { |
|
| 949 | + foreach ( $results as $result ) { |
|
| 950 | + $shortcodes[ ] = $result; |
|
| 951 | 951 | } |
| 952 | 952 | } |
| 953 | 953 | } |
@@ -1091,7 +1091,7 @@ discard block |
||
| 1091 | 1091 | public static function get_directory_fields( $post_id, $apply_filter = true ) { |
| 1092 | 1092 | $fields = get_post_meta( $post_id, '_gravityview_directory_fields', true ); |
| 1093 | 1093 | |
| 1094 | - if( $apply_filter ) { |
|
| 1094 | + if ( $apply_filter ) { |
|
| 1095 | 1095 | /** |
| 1096 | 1096 | * @filter `gravityview/configuration/fields` Filter the View fields' configuration array |
| 1097 | 1097 | * @since 1.6.5 |
@@ -1114,7 +1114,7 @@ discard block |
||
| 1114 | 1114 | * @return string html |
| 1115 | 1115 | */ |
| 1116 | 1116 | public static function get_sortable_fields( $formid, $current = '' ) { |
| 1117 | - $output = '<option value="" ' . selected( '', $current, false ).'>' . esc_html__( 'Default', 'gravityview' ) .'</option>'; |
|
| 1117 | + $output = '<option value="" ' . selected( '', $current, false ) . '>' . esc_html__( 'Default', 'gravityview' ) . '</option>'; |
|
| 1118 | 1118 | |
| 1119 | 1119 | if ( empty( $formid ) ) { |
| 1120 | 1120 | return $output; |
@@ -1127,11 +1127,11 @@ discard block |
||
| 1127 | 1127 | $blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array( 'list', 'textarea' ), null ); |
| 1128 | 1128 | |
| 1129 | 1129 | foreach ( $fields as $id => $field ) { |
| 1130 | - if ( in_array( $field['type'], $blacklist_field_types ) ) { |
|
| 1130 | + if ( in_array( $field[ 'type' ], $blacklist_field_types ) ) { |
|
| 1131 | 1131 | continue; |
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | - $output .= '<option value="'. $id .'" '. selected( $id, $current, false ).'>'. esc_attr( $field['label'] ) .'</option>'; |
|
| 1134 | + $output .= '<option value="' . $id . '" ' . selected( $id, $current, false ) . '>' . esc_attr( $field[ 'label' ] ) . '</option>'; |
|
| 1135 | 1135 | } |
| 1136 | 1136 | } |
| 1137 | 1137 | |
@@ -1166,9 +1166,9 @@ discard block |
||
| 1166 | 1166 | $blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', $blacklist, NULL ); |
| 1167 | 1167 | |
| 1168 | 1168 | // TODO: Convert to using array_filter |
| 1169 | - foreach( $fields as $id => $field ) { |
|
| 1169 | + foreach ( $fields as $id => $field ) { |
|
| 1170 | 1170 | |
| 1171 | - if( in_array( $field['type'], $blacklist_field_types ) ) { |
|
| 1171 | + if ( in_array( $field[ 'type' ], $blacklist_field_types ) ) { |
|
| 1172 | 1172 | unset( $fields[ $id ] ); |
| 1173 | 1173 | } |
| 1174 | 1174 | } |
@@ -1209,14 +1209,14 @@ discard block |
||
| 1209 | 1209 | * @param int|array $field field key or field array |
| 1210 | 1210 | * @return boolean |
| 1211 | 1211 | */ |
| 1212 | - public static function is_field_numeric( $form = null, $field = '' ) { |
|
| 1212 | + public static function is_field_numeric( $form = null, $field = '' ) { |
|
| 1213 | 1213 | |
| 1214 | 1214 | if ( ! is_array( $form ) && ! is_array( $field ) ) { |
| 1215 | 1215 | $form = self::get_form( $form ); |
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | 1218 | // If entry meta, it's a string. Otherwise, numeric |
| 1219 | - if( ! is_numeric( $field ) && is_string( $field ) ) { |
|
| 1219 | + if ( ! is_numeric( $field ) && is_string( $field ) ) { |
|
| 1220 | 1220 | $type = $field; |
| 1221 | 1221 | } else { |
| 1222 | 1222 | $type = self::get_field_type( $form, $field ); |
@@ -1230,9 +1230,9 @@ discard block |
||
| 1230 | 1230 | $numeric_types = apply_filters( 'gravityview/common/numeric_types', array( 'number', 'time' ) ); |
| 1231 | 1231 | |
| 1232 | 1232 | // Defer to GravityView_Field setting, if the field type is registered and `is_numeric` is true |
| 1233 | - if( $gv_field = GravityView_Fields::get( $type ) ) { |
|
| 1234 | - if( true === $gv_field->is_numeric ) { |
|
| 1235 | - $numeric_types[] = $gv_field->is_numeric; |
|
| 1233 | + if ( $gv_field = GravityView_Fields::get( $type ) ) { |
|
| 1234 | + if ( true === $gv_field->is_numeric ) { |
|
| 1235 | + $numeric_types[ ] = $gv_field->is_numeric; |
|
| 1236 | 1236 | } |
| 1237 | 1237 | } |
| 1238 | 1238 | |
@@ -1382,18 +1382,18 @@ discard block |
||
| 1382 | 1382 | $final_atts = array_filter( $final_atts ); |
| 1383 | 1383 | |
| 1384 | 1384 | // If the href wasn't passed as an attribute, use the value passed to the function |
| 1385 | - if ( empty( $final_atts['href'] ) && ! empty( $href ) ) { |
|
| 1386 | - $final_atts['href'] = $href; |
|
| 1385 | + if ( empty( $final_atts[ 'href' ] ) && ! empty( $href ) ) { |
|
| 1386 | + $final_atts[ 'href' ] = $href; |
|
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | - $final_atts['href'] = esc_url_raw( $href ); |
|
| 1389 | + $final_atts[ 'href' ] = esc_url_raw( $href ); |
|
| 1390 | 1390 | |
| 1391 | 1391 | /** |
| 1392 | 1392 | * Fix potential security issue with target=_blank |
| 1393 | 1393 | * @see https://dev.to/ben/the-targetblank-vulnerability-by-example |
| 1394 | 1394 | */ |
| 1395 | - if( '_blank' === rgar( $final_atts, 'target' ) ) { |
|
| 1396 | - $final_atts['rel'] = trim( rgar( $final_atts, 'rel', '' ) . ' noopener noreferrer' ); |
|
| 1395 | + if ( '_blank' === rgar( $final_atts, 'target' ) ) { |
|
| 1396 | + $final_atts[ 'rel' ] = trim( rgar( $final_atts, 'rel', '' ) . ' noopener noreferrer' ); |
|
| 1397 | 1397 | } |
| 1398 | 1398 | |
| 1399 | 1399 | // Sort the attributes alphabetically, to help testing |
@@ -1405,7 +1405,7 @@ discard block |
||
| 1405 | 1405 | $output .= sprintf( ' %s="%s"', $attr, esc_attr( $value ) ); |
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | - if( '' !== $output ) { |
|
| 1408 | + if ( '' !== $output ) { |
|
| 1409 | 1409 | $output = '<a' . $output . '>' . $anchor_text . '</a>'; |
| 1410 | 1410 | } |
| 1411 | 1411 | |
@@ -1432,7 +1432,7 @@ discard block |
||
| 1432 | 1432 | if ( is_array( $value ) && isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ) { |
| 1433 | 1433 | $merged[ $key ] = self::array_merge_recursive_distinct( $merged[ $key ], $value ); |
| 1434 | 1434 | } else if ( is_numeric( $key ) && isset( $merged[ $key ] ) ) { |
| 1435 | - $merged[] = $value; |
|
| 1435 | + $merged[ ] = $value; |
|
| 1436 | 1436 | } else { |
| 1437 | 1437 | $merged[ $key ] = $value; |
| 1438 | 1438 | } |
@@ -1465,7 +1465,7 @@ discard block |
||
| 1465 | 1465 | * `$context` is where are we using this information (e.g. change_entry_creator, search_widget ..) |
| 1466 | 1466 | * @param array $settings Settings array, with `number` key defining the # of users to display |
| 1467 | 1467 | */ |
| 1468 | - $get_users_settings = apply_filters( 'gravityview/get_users/'. $context, apply_filters( 'gravityview_change_entry_creator_user_parameters', $get_users_settings ) ); |
|
| 1468 | + $get_users_settings = apply_filters( 'gravityview/get_users/' . $context, apply_filters( 'gravityview_change_entry_creator_user_parameters', $get_users_settings ) ); |
|
| 1469 | 1469 | |
| 1470 | 1470 | return get_users( $get_users_settings ); |
| 1471 | 1471 | } |
@@ -1480,7 +1480,7 @@ discard block |
||
| 1480 | 1480 | * @return string |
| 1481 | 1481 | */ |
| 1482 | 1482 | public static function generate_notice( $notice, $class = '' ) { |
| 1483 | - return '<div class="gv-notice '.gravityview_sanitize_html_class( $class ) .'">'. $notice .'</div>'; |
|
| 1483 | + return '<div class="gv-notice ' . gravityview_sanitize_html_class( $class ) . '">' . $notice . '</div>'; |
|
| 1484 | 1484 | } |
| 1485 | 1485 | |
| 1486 | 1486 | /** |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | |
| 265 | - if( GFCommon::is_product_field( $field['type'] ) ){ |
|
| 265 | + if( GFCommon::is_product_field( $field['type'] ) ) { |
|
| 266 | 266 | $has_product_fields = true; |
| 267 | 267 | } |
| 268 | 268 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | $fields = array(); |
| 324 | 324 | |
| 325 | - foreach ( $extra_fields as $key => $field ){ |
|
| 325 | + foreach ( $extra_fields as $key => $field ) { |
|
| 326 | 326 | if ( ! empty( $only_default_column ) && ! empty( $field['is_default_column'] ) ) { |
| 327 | 327 | $fields[ $key ] = array( 'label' => $field['label'], 'type' => 'entry_meta' ); |
| 328 | 328 | } |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | * @return GF_Field|null Gravity Forms field object, or NULL: Gravity Forms GFFormsModel does not exist or field at $field_id doesn't exist. |
| 889 | 889 | */ |
| 890 | 890 | public static function get_field( $form, $field_id ) { |
| 891 | - if ( class_exists( 'GFFormsModel' ) ){ |
|
| 891 | + if ( class_exists( 'GFFormsModel' ) ) { |
|
| 892 | 892 | return GFFormsModel::get_field( $form, $field_id ); |
| 893 | 893 | } else { |
| 894 | 894 | return null; |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | $shortcodes = array(); |
| 936 | 936 | |
| 937 | 937 | preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ); |
| 938 | - if ( empty( $matches ) ){ |
|
| 938 | + if ( empty( $matches ) ) { |
|
| 939 | 939 | return false; |
| 940 | 940 | } |
| 941 | 941 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @return GV_License_Handler |
| 41 | 41 | */ |
| 42 | 42 | public static function get_instance( GravityView_Settings $GFAddOn ) { |
| 43 | - if( empty( self::$instance ) ) { |
|
| 43 | + if ( empty( self::$instance ) ) { |
|
| 44 | 44 | self::$instance = new self( $GFAddOn ); |
| 45 | 45 | } |
| 46 | 46 | return self::$instance; |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | public function refresh_license_status() { |
| 71 | 71 | |
| 72 | 72 | // Only perform on GravityView pages |
| 73 | - if( ! gravityview_is_admin_page() ) { |
|
| 73 | + if ( ! gravityview_is_admin_page() ) { |
|
| 74 | 74 | return; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // The transient is fresh; don't fetch. |
| 78 | - if( $status = get_transient( self::status_transient_key ) ) { |
|
| 78 | + if ( $status = get_transient( self::status_transient_key ) ) { |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -101,37 +101,37 @@ discard block |
||
| 101 | 101 | $status = trim( $this->Addon->get_app_setting( 'license_key_status' ) ); |
| 102 | 102 | $key = trim( $this->Addon->get_app_setting( 'license_key' ) ); |
| 103 | 103 | |
| 104 | - if( !empty( $key ) ) { |
|
| 104 | + if ( ! empty( $key ) ) { |
|
| 105 | 105 | $response = $this->Addon->get_app_setting( 'license_key_response' ); |
| 106 | - $response = is_array( $response ) ? (object) $response : json_decode( $response ); |
|
| 106 | + $response = is_array( $response ) ? (object)$response : json_decode( $response ); |
|
| 107 | 107 | } else { |
| 108 | 108 | $response = array(); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | wp_localize_script( 'gv-admin-edd-license', 'GVGlobals', array( |
| 112 | 112 | 'license_box' => $this->get_license_message( $response ) |
| 113 | - )); |
|
| 113 | + ) ); |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | $fields = array( |
| 117 | 117 | array( |
| 118 | 118 | 'name' => 'edd-activate', |
| 119 | - 'value' => __('Activate License', 'gravityview'), |
|
| 120 | - 'data-pending_text' => __('Verifying license…', 'gravityview'), |
|
| 119 | + 'value' => __( 'Activate License', 'gravityview' ), |
|
| 120 | + 'data-pending_text' => __( 'Verifying license…', 'gravityview' ), |
|
| 121 | 121 | 'data-edd_action' => 'activate_license', |
| 122 | 122 | 'class' => 'button-primary', |
| 123 | 123 | ), |
| 124 | 124 | array( |
| 125 | 125 | 'name' => 'edd-deactivate', |
| 126 | - 'value' => __('Deactivate License', 'gravityview'), |
|
| 127 | - 'data-pending_text' => __('Deactivating license…', 'gravityview'), |
|
| 126 | + 'value' => __( 'Deactivate License', 'gravityview' ), |
|
| 127 | + 'data-pending_text' => __( 'Deactivating license…', 'gravityview' ), |
|
| 128 | 128 | 'data-edd_action' => 'deactivate_license', |
| 129 | 129 | 'class' => ( empty( $status ) ? 'button-primary hide' : 'button-primary' ), |
| 130 | 130 | ), |
| 131 | 131 | array( |
| 132 | 132 | 'name' => 'edd-check', |
| 133 | - 'value' => __('Check License', 'gravityview'), |
|
| 134 | - 'data-pending_text' => __('Verifying license…', 'gravityview'), |
|
| 133 | + 'value' => __( 'Check License', 'gravityview' ), |
|
| 134 | + 'data-pending_text' => __( 'Verifying license…', 'gravityview' ), |
|
| 135 | 135 | 'title' => 'Check the license before saving it', |
| 136 | 136 | 'data-edd_action' => 'check_license', |
| 137 | 137 | 'class' => 'button-secondary', |
@@ -141,17 +141,17 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | $class = 'button gv-edd-action'; |
| 143 | 143 | |
| 144 | - $class .= ( !empty( $key ) && $status !== 'valid' ) ? '' : ' hide'; |
|
| 144 | + $class .= ( ! empty( $key ) && $status !== 'valid' ) ? '' : ' hide'; |
|
| 145 | 145 | |
| 146 | 146 | $disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled'; |
| 147 | 147 | |
| 148 | 148 | $submit = '<div class="gv-edd-button-wrapper">'; |
| 149 | 149 | foreach ( $fields as $field ) { |
| 150 | - $field['type'] = 'button'; |
|
| 151 | - $field['class'] = isset( $field['class'] ) ? $field['class'] . ' '. $class : $class; |
|
| 152 | - $field['style'] = 'margin-left: 10px;'; |
|
| 153 | - if( $disabled_attribute ) { |
|
| 154 | - $field['disabled'] = $disabled_attribute; |
|
| 150 | + $field[ 'type' ] = 'button'; |
|
| 151 | + $field[ 'class' ] = isset( $field[ 'class' ] ) ? $field[ 'class' ] . ' ' . $class : $class; |
|
| 152 | + $field[ 'style' ] = 'margin-left: 10px;'; |
|
| 153 | + if ( $disabled_attribute ) { |
|
| 154 | + $field[ 'disabled' ] = $disabled_attribute; |
|
| 155 | 155 | } |
| 156 | 156 | $submit .= $this->Addon->settings_submit( $field, $echo ); |
| 157 | 157 | } |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | private function setup_edd() { |
| 169 | 169 | |
| 170 | - if( !class_exists('EDD_SL_Plugin_Updater') ) { |
|
| 171 | - require_once( GRAVITYVIEW_DIR . 'includes/lib/EDD_SL_Plugin_Updater.php'); |
|
| 170 | + if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
|
| 171 | + require_once( GRAVITYVIEW_DIR . 'includes/lib/EDD_SL_Plugin_Updater.php' ); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // setup the updater |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | 'url' => home_url(), |
| 206 | 206 | ); |
| 207 | 207 | |
| 208 | - if( !empty( $action ) ) { |
|
| 209 | - $settings['edd_action'] = esc_attr( $action ); |
|
| 208 | + if ( ! empty( $action ) ) { |
|
| 209 | + $settings[ 'edd_action' ] = esc_attr( $action ); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $settings = array_map( 'urlencode', $settings ); |
@@ -220,14 +220,14 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | private function _license_get_remote_response( $data, $license = '' ) { |
| 222 | 222 | |
| 223 | - $api_params = $this->_get_edd_settings( $data['edd_action'], $license ); |
|
| 223 | + $api_params = $this->_get_edd_settings( $data[ 'edd_action' ], $license ); |
|
| 224 | 224 | |
| 225 | 225 | $url = add_query_arg( $api_params, self::url ); |
| 226 | 226 | |
| 227 | 227 | $response = wp_remote_get( $url, array( |
| 228 | 228 | 'timeout' => 15, |
| 229 | 229 | 'sslverify' => false, |
| 230 | - )); |
|
| 230 | + ) ); |
|
| 231 | 231 | |
| 232 | 232 | if ( is_wp_error( $response ) ) { |
| 233 | 233 | return array(); |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | function get_license_message( $license_data ) { |
| 262 | 262 | |
| 263 | - if( empty( $license_data ) ) { |
|
| 263 | + if ( empty( $license_data ) ) { |
|
| 264 | 264 | $message = ''; |
| 265 | 265 | } else { |
| 266 | 266 | |
| 267 | - if( ! empty( $license_data->error ) ) { |
|
| 267 | + if ( ! empty( $license_data->error ) ) { |
|
| 268 | 268 | $class = 'error'; |
| 269 | 269 | $string_key = $license_data->error; |
| 270 | 270 | } else { |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | $string_key = $license_data->license; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $message = sprintf( '<p><strong>%s: %s</strong></p>', $this->strings('status'), $this->strings( $string_key, $license_data ) ); |
|
| 275 | + $message = sprintf( '<p><strong>%s: %s</strong></p>', $this->strings( 'status' ), $this->strings( $string_key, $license_data ) ); |
|
| 276 | 276 | |
| 277 | 277 | $message = $this->generate_license_box( $message, $class ); |
| 278 | 278 | } |
@@ -309,18 +309,18 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | public function license_details( $response = array() ) { |
| 311 | 311 | |
| 312 | - $response = (array) $response; |
|
| 312 | + $response = (array)$response; |
|
| 313 | 313 | |
| 314 | 314 | $return = ''; |
| 315 | 315 | $wrapper = '<span class="gv-license-details" aria-live="polite" aria-busy="false">%s</span>'; |
| 316 | 316 | |
| 317 | - if( ! empty( $response['license_key'] ) ) { |
|
| 317 | + if ( ! empty( $response[ 'license_key' ] ) ) { |
|
| 318 | 318 | |
| 319 | 319 | $return .= '<h3>' . esc_html__( 'License Details:', 'gravityview' ) . '</h3>'; |
| 320 | 320 | |
| 321 | 321 | if ( in_array( rgar( $response, 'license' ), array( 'invalid', 'deactivated' ) ) ) { |
| 322 | - $return .= $this->strings( $response['license'], $response ); |
|
| 323 | - } elseif ( ! empty( $response['license_name'] ) ) { |
|
| 322 | + $return .= $this->strings( $response[ 'license' ], $response ); |
|
| 323 | + } elseif ( ! empty( $response[ 'license_name' ] ) ) { |
|
| 324 | 324 | |
| 325 | 325 | $response_keys = array( |
| 326 | 326 | 'license_name' => '', |
@@ -335,19 +335,19 @@ discard block |
||
| 335 | 335 | // Make sure all the keys are set |
| 336 | 336 | $response = wp_parse_args( $response, $response_keys ); |
| 337 | 337 | |
| 338 | - $login_link = sprintf( '<a href="%s" class="howto" rel="external">%s</a>', esc_url( sprintf( 'https://gravityview.co/wp-login.php?username=%s', $response['customer_email'] ) ), esc_html__( 'Access your GravityView account', 'gravityview' ) ); |
|
| 339 | - $local_text = ( ! empty( $response['is_local'] ) ? '<span class="howto">' . __( 'This development site does not count toward license activation limits', 'gravityview' ) . '</span>' : '' ); |
|
| 338 | + $login_link = sprintf( '<a href="%s" class="howto" rel="external">%s</a>', esc_url( sprintf( 'https://gravityview.co/wp-login.php?username=%s', $response[ 'customer_email' ] ) ), esc_html__( 'Access your GravityView account', 'gravityview' ) ); |
|
| 339 | + $local_text = ( ! empty( $response[ 'is_local' ] ) ? '<span class="howto">' . __( 'This development site does not count toward license activation limits', 'gravityview' ) . '</span>' : '' ); |
|
| 340 | 340 | $details = array( |
| 341 | - 'license' => sprintf( esc_html__( 'License level: %s', 'gravityview' ), esc_html( $response['license_name'] ), esc_html( $response['license_limit'] ) ), |
|
| 342 | - 'licensed_to' => sprintf( esc_html_x( 'Licensed to: %1$s (%2$s)', '1: Customer name; 2: Customer email', 'gravityview' ), esc_html__( $response['customer_name'], 'gravityview' ), esc_html__( $response['customer_email'], 'gravityview' ) ) . $login_link, |
|
| 343 | - 'activations' => sprintf( esc_html__( 'Activations: %d of %s sites', 'gravityview' ), intval( $response['site_count'] ), esc_html( $response['license_limit'] ) ) . $local_text, |
|
| 344 | - 'expires' => sprintf( esc_html__( 'Renew on: %s', 'gravityview' ), date_i18n( get_option( 'date_format' ), strtotime( $response['expires'] ) - DAY_IN_SECONDS ) ), |
|
| 345 | - 'upgrade' => $this->get_upgrade_html( $response['upgrades'] ), |
|
| 341 | + 'license' => sprintf( esc_html__( 'License level: %s', 'gravityview' ), esc_html( $response[ 'license_name' ] ), esc_html( $response[ 'license_limit' ] ) ), |
|
| 342 | + 'licensed_to' => sprintf( esc_html_x( 'Licensed to: %1$s (%2$s)', '1: Customer name; 2: Customer email', 'gravityview' ), esc_html__( $response[ 'customer_name' ], 'gravityview' ), esc_html__( $response[ 'customer_email' ], 'gravityview' ) ) . $login_link, |
|
| 343 | + 'activations' => sprintf( esc_html__( 'Activations: %d of %s sites', 'gravityview' ), intval( $response[ 'site_count' ] ), esc_html( $response[ 'license_limit' ] ) ) . $local_text, |
|
| 344 | + 'expires' => sprintf( esc_html__( 'Renew on: %s', 'gravityview' ), date_i18n( get_option( 'date_format' ), strtotime( $response[ 'expires' ] ) - DAY_IN_SECONDS ) ), |
|
| 345 | + 'upgrade' => $this->get_upgrade_html( $response[ 'upgrades' ] ), |
|
| 346 | 346 | ); |
| 347 | 347 | |
| 348 | - if ( ! empty( $response['error'] ) && 'expired' === $response['error'] ) { |
|
| 349 | - unset( $details['upgrade'] ); |
|
| 350 | - $details['expires'] = '<div class="error inline"><p>' . $this->strings( 'expired', $response ) . '</p></div>'; |
|
| 348 | + if ( ! empty( $response[ 'error' ] ) && 'expired' === $response[ 'error' ] ) { |
|
| 349 | + unset( $details[ 'upgrade' ] ); |
|
| 350 | + $details[ 'expires' ] = '<div class="error inline"><p>' . $this->strings( 'expired', $response ) . '</p></div>'; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | $return .= '<ul><li>' . implode( '</li><li>', array_filter( $details ) ) . '</li></ul>'; |
@@ -370,11 +370,11 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | $output = ''; |
| 372 | 372 | |
| 373 | - if( ! empty( $upgrades ) ) { |
|
| 373 | + if ( ! empty( $upgrades ) ) { |
|
| 374 | 374 | |
| 375 | 375 | $locale_parts = explode( '_', get_locale() ); |
| 376 | 376 | |
| 377 | - $is_english = ( 'en' === $locale_parts[0] ); |
|
| 377 | + $is_english = ( 'en' === $locale_parts[ 0 ] ); |
|
| 378 | 378 | |
| 379 | 379 | $output .= '<h4>' . esc_html__( 'Upgrades available:', 'gravityview' ) . '</h4>'; |
| 380 | 380 | |
@@ -382,14 +382,14 @@ discard block |
||
| 382 | 382 | |
| 383 | 383 | foreach ( $upgrades as $upgrade_id => $upgrade ) { |
| 384 | 384 | |
| 385 | - $upgrade = (object) $upgrade; |
|
| 385 | + $upgrade = (object)$upgrade; |
|
| 386 | 386 | |
| 387 | 387 | $anchor_text = sprintf( esc_html_x( 'Upgrade to %1$s for %2$s', '1: GravityView upgrade name, 2: Cost of upgrade', 'gravityview' ), esc_attr( $upgrade->name ), esc_attr( $upgrade->price ) ); |
| 388 | 388 | |
| 389 | - if( $is_english && isset( $upgrade->description ) ) { |
|
| 389 | + if ( $is_english && isset( $upgrade->description ) ) { |
|
| 390 | 390 | $message = esc_html( $upgrade->description ); |
| 391 | 391 | } else { |
| 392 | - switch( $upgrade->price_id ) { |
|
| 392 | + switch ( $upgrade->price_id ) { |
|
| 393 | 393 | // Interstellar |
| 394 | 394 | case 1: |
| 395 | 395 | default: |
@@ -427,16 +427,16 @@ discard block |
||
| 427 | 427 | */ |
| 428 | 428 | public function license_call( $array = array() ) { |
| 429 | 429 | |
| 430 | - $is_ajax = ( defined('DOING_AJAX') && DOING_AJAX ); |
|
| 431 | - $data = empty( $array ) ? $_POST['data'] : $array; |
|
| 430 | + $is_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
| 431 | + $data = empty( $array ) ? $_POST[ 'data' ] : $array; |
|
| 432 | 432 | $has_cap = GVCommon::has_cap( 'gravityview_edit_settings' ); |
| 433 | 433 | |
| 434 | - if ( $is_ajax && empty( $data['license'] ) ) { |
|
| 435 | - die( - 1 ); |
|
| 434 | + if ( $is_ajax && empty( $data[ 'license' ] ) ) { |
|
| 435 | + die( -1 ); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | // If the user isn't allowed to edit settings, show an error message |
| 439 | - if( ! $has_cap ) { |
|
| 439 | + if ( ! $has_cap ) { |
|
| 440 | 440 | $license_data = new stdClass(); |
| 441 | 441 | $license_data->error = 'capability'; |
| 442 | 442 | $license_data->message = $this->get_license_message( $license_data ); |
@@ -460,9 +460,9 @@ discard block |
||
| 460 | 460 | |
| 461 | 461 | $json = json_encode( $license_data ); |
| 462 | 462 | |
| 463 | - $update_license = ( ! isset( $data['update'] ) || ! empty( $data['update'] ) ); |
|
| 463 | + $update_license = ( ! isset( $data[ 'update' ] ) || ! empty( $data[ 'update' ] ) ); |
|
| 464 | 464 | |
| 465 | - $is_check_action_button = ( 'check_license' === $data['edd_action'] && defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
| 465 | + $is_check_action_button = ( 'check_license' === $data[ 'edd_action' ] && defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
| 466 | 466 | |
| 467 | 467 | // Failed is the response from trying to de-activate a license and it didn't work. |
| 468 | 468 | // This likely happened because people entered in a different key and clicked "Deactivate", |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | // most likely a mistake. |
| 471 | 471 | if ( $license_data->license !== 'failed' && ! $is_check_action_button && $update_license ) { |
| 472 | 472 | |
| 473 | - if ( ! empty( $data['field_id'] ) ) { |
|
| 473 | + if ( ! empty( $data[ 'field_id' ] ) ) { |
|
| 474 | 474 | set_transient( self::status_transient_key, $license_data, DAY_IN_SECONDS ); |
| 475 | 475 | } |
| 476 | 476 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | if ( $is_ajax ) { |
| 482 | 482 | exit( $json ); |
| 483 | 483 | } else { // Non-ajax call |
| 484 | - return ( rgget('format', $data ) === 'object' ) ? $license_data : $json; |
|
| 484 | + return ( rgget( 'format', $data ) === 'object' ) ? $license_data : $json; |
|
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
@@ -495,9 +495,9 @@ discard block |
||
| 495 | 495 | // Update option with passed data license |
| 496 | 496 | $settings = $this->Addon->get_app_settings(); |
| 497 | 497 | |
| 498 | - $settings['license_key'] = $license_data->license_key = trim( $data['license'] ); |
|
| 499 | - $settings['license_key_status'] = $license_data->license; |
|
| 500 | - $settings['license_key_response'] = (array)$license_data; |
|
| 498 | + $settings[ 'license_key' ] = $license_data->license_key = trim( $data[ 'license' ] ); |
|
| 499 | + $settings[ 'license_key_status' ] = $license_data->license; |
|
| 500 | + $settings[ 'license_key_response' ] = (array)$license_data; |
|
| 501 | 501 | |
| 502 | 502 | $this->Addon->update_app_settings( $settings ); |
| 503 | 503 | } |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | */ |
| 511 | 511 | private function get_license_renewal_url( $license_data ) { |
| 512 | 512 | $license_data = is_array( $license_data ) ? (object)$license_data : $license_data; |
| 513 | - $renew_license_url = ( ! empty( $license_data ) && !empty( $license_data->license_key ) ) ? sprintf( 'https://gravityview.co/checkout/?download_id=17&edd_license_key=%s&utm_source=admin_notice&utm_medium=admin&utm_content=expired&utm_campaign=Activation&force_login=1', $license_data->license_key ) : 'https://gravityview.co/account/'; |
|
| 513 | + $renew_license_url = ( ! empty( $license_data ) && ! empty( $license_data->license_key ) ) ? sprintf( 'https://gravityview.co/checkout/?download_id=17&edd_license_key=%s&utm_source=admin_notice&utm_medium=admin&utm_content=expired&utm_campaign=Activation&force_login=1', $license_data->license_key ) : 'https://gravityview.co/account/'; |
|
| 514 | 514 | return $renew_license_url; |
| 515 | 515 | } |
| 516 | 516 | |
@@ -525,31 +525,31 @@ discard block |
||
| 525 | 525 | |
| 526 | 526 | |
| 527 | 527 | $strings = array( |
| 528 | - 'status' => esc_html__('Status', 'gravityview'), |
|
| 529 | - 'error' => esc_html__('There was an error processing the request.', 'gravityview'), |
|
| 530 | - 'failed' => esc_html__('Could not deactivate the license. The license key you attempted to deactivate may not be active or valid.', 'gravityview'), |
|
| 531 | - 'site_inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'), |
|
| 532 | - 'inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'), |
|
| 533 | - 'no_activations_left' => esc_html__('Invalid: this license has reached its activation limit.', 'gravityview') . ' ' . sprintf( esc_html__('You can manage license activations %son your GravityView account page%s.', 'gravityview'), '<a href="https://gravityview.co/account/#licenses">', '</a>' ), |
|
| 534 | - 'deactivated' => esc_html__('The license has been deactivated.', 'gravityview'), |
|
| 535 | - 'valid' => esc_html__('The license key is valid and active.', 'gravityview'), |
|
| 536 | - 'invalid' => esc_html__('The license key entered is invalid.', 'gravityview'), |
|
| 537 | - 'missing' => esc_html__('Invalid license key.', 'gravityview'), |
|
| 538 | - 'revoked' => esc_html__('This license key has been revoked.', 'gravityview'), |
|
| 539 | - 'expired' => sprintf( esc_html__('This license key has expired. %sRenew your license on the GravityView website%s to receive updates and support.', 'gravityview'), '<a href="'. esc_url( $this->get_license_renewal_url( $license_data ) ) .'">', '</a>' ), |
|
| 528 | + 'status' => esc_html__( 'Status', 'gravityview' ), |
|
| 529 | + 'error' => esc_html__( 'There was an error processing the request.', 'gravityview' ), |
|
| 530 | + 'failed' => esc_html__( 'Could not deactivate the license. The license key you attempted to deactivate may not be active or valid.', 'gravityview' ), |
|
| 531 | + 'site_inactive' => esc_html__( 'The license key is valid, but it has not been activated for this site.', 'gravityview' ), |
|
| 532 | + 'inactive' => esc_html__( 'The license key is valid, but it has not been activated for this site.', 'gravityview' ), |
|
| 533 | + 'no_activations_left' => esc_html__( 'Invalid: this license has reached its activation limit.', 'gravityview' ) . ' ' . sprintf( esc_html__( 'You can manage license activations %son your GravityView account page%s.', 'gravityview' ), '<a href="https://gravityview.co/account/#licenses">', '</a>' ), |
|
| 534 | + 'deactivated' => esc_html__( 'The license has been deactivated.', 'gravityview' ), |
|
| 535 | + 'valid' => esc_html__( 'The license key is valid and active.', 'gravityview' ), |
|
| 536 | + 'invalid' => esc_html__( 'The license key entered is invalid.', 'gravityview' ), |
|
| 537 | + 'missing' => esc_html__( 'Invalid license key.', 'gravityview' ), |
|
| 538 | + 'revoked' => esc_html__( 'This license key has been revoked.', 'gravityview' ), |
|
| 539 | + 'expired' => sprintf( esc_html__( 'This license key has expired. %sRenew your license on the GravityView website%s to receive updates and support.', 'gravityview' ), '<a href="' . esc_url( $this->get_license_renewal_url( $license_data ) ) . '">', '</a>' ), |
|
| 540 | 540 | 'capability' => esc_html__( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ), |
| 541 | 541 | |
| 542 | - 'verifying_license' => esc_html__('Verifying license…', 'gravityview'), |
|
| 543 | - 'activate_license' => esc_html__('Activate License', 'gravityview'), |
|
| 544 | - 'deactivate_license' => esc_html__('Deactivate License', 'gravityview'), |
|
| 545 | - 'check_license' => esc_html__('Verify License', 'gravityview'), |
|
| 542 | + 'verifying_license' => esc_html__( 'Verifying license…', 'gravityview' ), |
|
| 543 | + 'activate_license' => esc_html__( 'Activate License', 'gravityview' ), |
|
| 544 | + 'deactivate_license' => esc_html__( 'Deactivate License', 'gravityview' ), |
|
| 545 | + 'check_license' => esc_html__( 'Verify License', 'gravityview' ), |
|
| 546 | 546 | ); |
| 547 | 547 | |
| 548 | - if( empty( $status ) ) { |
|
| 548 | + if ( empty( $status ) ) { |
|
| 549 | 549 | return $strings; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - if( isset( $strings[ $status ] ) ) { |
|
| 552 | + if ( isset( $strings[ $status ] ) ) { |
|
| 553 | 553 | return $strings[ $status ]; |
| 554 | 554 | } |
| 555 | 555 | |
@@ -10,21 +10,21 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | if ( ! defined( 'WPINC' ) ) { |
| 13 | - die; |
|
| 13 | + die; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | class GravityView_Edit_Entry_Render { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var GravityView_Edit_Entry |
|
| 21 | - */ |
|
| 22 | - protected $loader; |
|
| 19 | + /** |
|
| 20 | + * @var GravityView_Edit_Entry |
|
| 21 | + */ |
|
| 22 | + protected $loader; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * @var string String used to generate unique nonce for the entry/form/view combination. Allows access to edit page. |
| 26 | 26 | */ |
| 27 | - static $nonce_key; |
|
| 27 | + static $nonce_key; |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @since 1.9 |
@@ -44,12 +44,12 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | private static $supports_product_fields = false; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Gravity Forms entry array |
|
| 49 | - * |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - public $entry; |
|
| 47 | + /** |
|
| 48 | + * Gravity Forms entry array |
|
| 49 | + * |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + public $entry; |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Gravity Forms entry array (it won't get changed during this class lifecycle) |
@@ -58,135 +58,135 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | private static $original_entry = array(); |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Gravity Forms form array (GravityView modifies the content through this class lifecycle) |
|
| 63 | - * |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 61 | + /** |
|
| 62 | + * Gravity Forms form array (GravityView modifies the content through this class lifecycle) |
|
| 63 | + * |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | 66 | public $form; |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Gravity Forms form array (it won't get changed during this class lifecycle) |
|
| 70 | - * @since 1.16.2.1 |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - private static $original_form; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Gravity Forms form array after the form validation process |
|
| 77 | - * @since 1.13 |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 68 | + /** |
|
| 69 | + * Gravity Forms form array (it won't get changed during this class lifecycle) |
|
| 70 | + * @since 1.16.2.1 |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + private static $original_form; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Gravity Forms form array after the form validation process |
|
| 77 | + * @since 1.13 |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | 80 | public $form_after_validation = null; |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Hold an array of GF field objects that have calculation rules |
|
| 84 | - * @var array |
|
| 85 | - */ |
|
| 82 | + /** |
|
| 83 | + * Hold an array of GF field objects that have calculation rules |
|
| 84 | + * @var array |
|
| 85 | + */ |
|
| 86 | 86 | public $fields_with_calculation = array(); |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Hold an array of GF field objects with type 'total' |
|
| 90 | - * @var array |
|
| 91 | - */ |
|
| 88 | + /** |
|
| 89 | + * Hold an array of GF field objects with type 'total' |
|
| 90 | + * @var array |
|
| 91 | + */ |
|
| 92 | 92 | public $total_fields = array(); |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Gravity Forms form id |
|
| 96 | - * |
|
| 97 | - * @var int |
|
| 98 | - */ |
|
| 94 | + /** |
|
| 95 | + * Gravity Forms form id |
|
| 96 | + * |
|
| 97 | + * @var int |
|
| 98 | + */ |
|
| 99 | 99 | public $form_id; |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * ID of the current view |
|
| 103 | - * |
|
| 104 | - * @var int |
|
| 105 | - */ |
|
| 101 | + /** |
|
| 102 | + * ID of the current view |
|
| 103 | + * |
|
| 104 | + * @var int |
|
| 105 | + */ |
|
| 106 | 106 | public $view_id; |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Updated entry is valid (GF Validation object) |
|
| 110 | - * |
|
| 111 | - * @var array |
|
| 112 | - */ |
|
| 108 | + /** |
|
| 109 | + * Updated entry is valid (GF Validation object) |
|
| 110 | + * |
|
| 111 | + * @var array |
|
| 112 | + */ |
|
| 113 | 113 | public $is_valid = NULL; |
| 114 | 114 | |
| 115 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
| 116 | - $this->loader = $loader; |
|
| 117 | - } |
|
| 115 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
| 116 | + $this->loader = $loader; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - function load() { |
|
| 119 | + function load() { |
|
| 120 | 120 | |
| 121 | - /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
| 122 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 121 | + /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
| 122 | + include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 123 | 123 | |
| 124 | - // Don't display an embedded form when editing an entry |
|
| 125 | - add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
|
| 126 | - add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
|
| 124 | + // Don't display an embedded form when editing an entry |
|
| 125 | + add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
|
| 126 | + add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
|
| 127 | 127 | |
| 128 | - // Stop Gravity Forms processing what is ours! |
|
| 129 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 128 | + // Stop Gravity Forms processing what is ours! |
|
| 129 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 130 | 130 | |
| 131 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 131 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 132 | 132 | |
| 133 | - add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
| 133 | + add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
| 134 | 134 | |
| 135 | - // Disable conditional logic if needed (since 1.9) |
|
| 136 | - add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
| 135 | + // Disable conditional logic if needed (since 1.9) |
|
| 136 | + add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
| 137 | 137 | |
| 138 | - // Make sure GF doesn't validate max files (since 1.9) |
|
| 139 | - add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
| 138 | + // Make sure GF doesn't validate max files (since 1.9) |
|
| 139 | + add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
| 140 | 140 | |
| 141 | - // Add fields expected by GFFormDisplay::validate() |
|
| 142 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 141 | + // Add fields expected by GFFormDisplay::validate() |
|
| 142 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 143 | 143 | |
| 144 | - } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Don't show any forms embedded on a page when GravityView is in Edit Entry mode |
|
| 148 | - * |
|
| 149 | - * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action |
|
| 150 | - * And then removes it on the `wp_footer` action |
|
| 151 | - * |
|
| 152 | - * @since 1.16.1 |
|
| 153 | - * |
|
| 154 | - * @return void |
|
| 155 | - */ |
|
| 156 | - public function prevent_render_form() { |
|
| 157 | - if( $this->is_edit_entry() ) { |
|
| 158 | - if( 'wp_head' === current_filter() ) { |
|
| 159 | - add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 160 | - } else { |
|
| 161 | - remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 146 | + /** |
|
| 147 | + * Don't show any forms embedded on a page when GravityView is in Edit Entry mode |
|
| 148 | + * |
|
| 149 | + * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action |
|
| 150 | + * And then removes it on the `wp_footer` action |
|
| 151 | + * |
|
| 152 | + * @since 1.16.1 |
|
| 153 | + * |
|
| 154 | + * @return void |
|
| 155 | + */ |
|
| 156 | + public function prevent_render_form() { |
|
| 157 | + if( $this->is_edit_entry() ) { |
|
| 158 | + if( 'wp_head' === current_filter() ) { |
|
| 159 | + add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 160 | + } else { |
|
| 161 | + remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
| 168 | - * backend form, we need to prevent them from saving twice. |
|
| 169 | - * @return void |
|
| 170 | - */ |
|
| 171 | - public function prevent_maybe_process_form() { |
|
| 166 | + /** |
|
| 167 | + * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
| 168 | + * backend form, we need to prevent them from saving twice. |
|
| 169 | + * @return void |
|
| 170 | + */ |
|
| 171 | + public function prevent_maybe_process_form() { |
|
| 172 | 172 | |
| 173 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 173 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 174 | 174 | |
| 175 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 176 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 177 | - } |
|
| 178 | - } |
|
| 175 | + if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 176 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Is the current page an Edit Entry page? |
|
| 182 | - * @return boolean |
|
| 183 | - */ |
|
| 184 | - public function is_edit_entry() { |
|
| 180 | + /** |
|
| 181 | + * Is the current page an Edit Entry page? |
|
| 182 | + * @return boolean |
|
| 183 | + */ |
|
| 184 | + public function is_edit_entry() { |
|
| 185 | 185 | |
| 186 | - $is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] ); |
|
| 186 | + $is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] ); |
|
| 187 | 187 | |
| 188 | - return ( $is_edit_entry || $this->is_edit_entry_submission() ); |
|
| 189 | - } |
|
| 188 | + return ( $is_edit_entry || $this->is_edit_entry_submission() ); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | 192 | * Is the current page an Edit Entry page? |
@@ -197,659 +197,659 @@ discard block |
||
| 197 | 197 | return !empty( $_POST[ self::$nonce_field ] ); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * When Edit entry view is requested setup the vars |
|
| 202 | - */ |
|
| 203 | - private function setup_vars() { |
|
| 204 | - $gravityview_view = GravityView_View::getInstance(); |
|
| 200 | + /** |
|
| 201 | + * When Edit entry view is requested setup the vars |
|
| 202 | + */ |
|
| 203 | + private function setup_vars() { |
|
| 204 | + $gravityview_view = GravityView_View::getInstance(); |
|
| 205 | 205 | |
| 206 | 206 | |
| 207 | - $entries = $gravityview_view->getEntries(); |
|
| 208 | - self::$original_entry = $entries[0]; |
|
| 209 | - $this->entry = $entries[0]; |
|
| 207 | + $entries = $gravityview_view->getEntries(); |
|
| 208 | + self::$original_entry = $entries[0]; |
|
| 209 | + $this->entry = $entries[0]; |
|
| 210 | 210 | |
| 211 | - self::$original_form = $gravityview_view->getForm(); |
|
| 212 | - $this->form = $gravityview_view->getForm(); |
|
| 213 | - $this->form_id = $gravityview_view->getFormId(); |
|
| 214 | - $this->view_id = $gravityview_view->getViewId(); |
|
| 211 | + self::$original_form = $gravityview_view->getForm(); |
|
| 212 | + $this->form = $gravityview_view->getForm(); |
|
| 213 | + $this->form_id = $gravityview_view->getFormId(); |
|
| 214 | + $this->view_id = $gravityview_view->getViewId(); |
|
| 215 | 215 | |
| 216 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 217 | - } |
|
| 216 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Load required files and trigger edit flow |
|
| 222 | - * |
|
| 223 | - * Run when the is_edit_entry returns true. |
|
| 224 | - * |
|
| 225 | - * @param GravityView_View_Data $gv_data GravityView Data object |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - public function init( $gv_data ) { |
|
| 220 | + /** |
|
| 221 | + * Load required files and trigger edit flow |
|
| 222 | + * |
|
| 223 | + * Run when the is_edit_entry returns true. |
|
| 224 | + * |
|
| 225 | + * @param GravityView_View_Data $gv_data GravityView Data object |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + public function init( $gv_data ) { |
|
| 229 | 229 | |
| 230 | - require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
| 231 | - require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
| 230 | + require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
| 231 | + require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
| 232 | 232 | |
| 233 | - $this->setup_vars(); |
|
| 233 | + $this->setup_vars(); |
|
| 234 | 234 | |
| 235 | - // Multiple Views embedded, don't proceed if nonce fails |
|
| 236 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 237 | - do_action('gravityview_log_error', __METHOD__ . ': Nonce validation failed for the Edit Entry request; returning' ); |
|
| 238 | - return; |
|
| 239 | - } |
|
| 235 | + // Multiple Views embedded, don't proceed if nonce fails |
|
| 236 | + if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 237 | + do_action('gravityview_log_error', __METHOD__ . ': Nonce validation failed for the Edit Entry request; returning' ); |
|
| 238 | + return; |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - // Sorry, you're not allowed here. |
|
| 242 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
| 243 | - do_action('gravityview_log_error', __METHOD__ . ': User is not allowed to edit this entry; returning', $this->entry ); |
|
| 244 | - return; |
|
| 245 | - } |
|
| 241 | + // Sorry, you're not allowed here. |
|
| 242 | + if( false === $this->user_can_edit_entry( true ) ) { |
|
| 243 | + do_action('gravityview_log_error', __METHOD__ . ': User is not allowed to edit this entry; returning', $this->entry ); |
|
| 244 | + return; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - $this->print_scripts(); |
|
| 247 | + $this->print_scripts(); |
|
| 248 | 248 | |
| 249 | - $this->process_save(); |
|
| 249 | + $this->process_save(); |
|
| 250 | 250 | |
| 251 | - $this->edit_entry_form(); |
|
| 251 | + $this->edit_entry_form(); |
|
| 252 | 252 | |
| 253 | - } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Force Gravity Forms to output scripts as if it were in the admin |
|
| 258 | - * @return void |
|
| 259 | - */ |
|
| 260 | - private function print_scripts() { |
|
| 261 | - $gravityview_view = GravityView_View::getInstance(); |
|
| 256 | + /** |
|
| 257 | + * Force Gravity Forms to output scripts as if it were in the admin |
|
| 258 | + * @return void |
|
| 259 | + */ |
|
| 260 | + private function print_scripts() { |
|
| 261 | + $gravityview_view = GravityView_View::getInstance(); |
|
| 262 | 262 | |
| 263 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 263 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 264 | 264 | |
| 265 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 265 | + GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 266 | 266 | |
| 267 | - // Sack is required for images |
|
| 268 | - wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
| 269 | - } |
|
| 267 | + // Sack is required for images |
|
| 268 | + wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Process edit entry form save |
|
| 274 | - */ |
|
| 275 | - private function process_save() { |
|
| 272 | + /** |
|
| 273 | + * Process edit entry form save |
|
| 274 | + */ |
|
| 275 | + private function process_save() { |
|
| 276 | 276 | |
| 277 | - if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) { |
|
| 278 | - return; |
|
| 279 | - } |
|
| 277 | + if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - // Make sure the entry, view, and form IDs are all correct |
|
| 282 | - $valid = $this->verify_nonce(); |
|
| 281 | + // Make sure the entry, view, and form IDs are all correct |
|
| 282 | + $valid = $this->verify_nonce(); |
|
| 283 | 283 | |
| 284 | - if( !$valid ) { |
|
| 285 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 286 | - return; |
|
| 287 | - } |
|
| 284 | + if( !$valid ) { |
|
| 285 | + do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 286 | + return; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 290 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 291 | - return; |
|
| 292 | - } |
|
| 289 | + if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 290 | + do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 291 | + return; |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - do_action('gravityview_log_debug', __METHOD__ . ': $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 294 | + do_action('gravityview_log_debug', __METHOD__ . ': $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 295 | 295 | |
| 296 | - $this->process_save_process_files( $this->form_id ); |
|
| 296 | + $this->process_save_process_files( $this->form_id ); |
|
| 297 | 297 | |
| 298 | - $this->validate(); |
|
| 298 | + $this->validate(); |
|
| 299 | 299 | |
| 300 | - if( $this->is_valid ) { |
|
| 300 | + if( $this->is_valid ) { |
|
| 301 | 301 | |
| 302 | - do_action('gravityview_log_debug', __METHOD__ . ': Submission is valid.' ); |
|
| 302 | + do_action('gravityview_log_debug', __METHOD__ . ': Submission is valid.' ); |
|
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields |
|
| 306 | - */ |
|
| 307 | - $form = $this->form_prepare_for_save(); |
|
| 304 | + /** |
|
| 305 | + * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields |
|
| 306 | + */ |
|
| 307 | + $form = $this->form_prepare_for_save(); |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
| 311 | - */ |
|
| 312 | - unset( $_GET['page'] ); |
|
| 309 | + /** |
|
| 310 | + * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
| 311 | + */ |
|
| 312 | + unset( $_GET['page'] ); |
|
| 313 | 313 | |
| 314 | - $date_created = $this->entry['date_created']; |
|
| 314 | + $date_created = $this->entry['date_created']; |
|
| 315 | 315 | |
| 316 | - /** |
|
| 317 | - * @hack to force Gravity Forms to use $read_value_from_post in GFFormsModel::save_lead() |
|
| 318 | - * @since 1.17.2 |
|
| 319 | - */ |
|
| 320 | - unset( $this->entry['date_created'] ); |
|
| 316 | + /** |
|
| 317 | + * @hack to force Gravity Forms to use $read_value_from_post in GFFormsModel::save_lead() |
|
| 318 | + * @since 1.17.2 |
|
| 319 | + */ |
|
| 320 | + unset( $this->entry['date_created'] ); |
|
| 321 | 321 | |
| 322 | - GFFormsModel::save_lead( $form, $this->entry ); |
|
| 322 | + GFFormsModel::save_lead( $form, $this->entry ); |
|
| 323 | 323 | |
| 324 | - // Delete the values for hidden inputs |
|
| 325 | - $this->unset_hidden_field_values(); |
|
| 324 | + // Delete the values for hidden inputs |
|
| 325 | + $this->unset_hidden_field_values(); |
|
| 326 | 326 | |
| 327 | - $this->entry['date_created'] = $date_created; |
|
| 327 | + $this->entry['date_created'] = $date_created; |
|
| 328 | 328 | |
| 329 | - // Process calculation fields |
|
| 330 | - $this->update_calculation_fields(); |
|
| 329 | + // Process calculation fields |
|
| 330 | + $this->update_calculation_fields(); |
|
| 331 | 331 | |
| 332 | - // Perform actions normally performed after updating a lead |
|
| 333 | - $this->after_update(); |
|
| 332 | + // Perform actions normally performed after updating a lead |
|
| 333 | + $this->after_update(); |
|
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * Must be AFTER after_update()! |
|
| 337 | - * @see https://github.com/gravityview/GravityView/issues/764 |
|
| 338 | - */ |
|
| 339 | - $this->maybe_update_post_fields( $form ); |
|
| 335 | + /** |
|
| 336 | + * Must be AFTER after_update()! |
|
| 337 | + * @see https://github.com/gravityview/GravityView/issues/764 |
|
| 338 | + */ |
|
| 339 | + $this->maybe_update_post_fields( $form ); |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
| 343 | - * @param array $form Gravity Forms form array |
|
| 344 | - * @param string $entry_id Numeric ID of the entry that was updated |
|
| 345 | - */ |
|
| 346 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 341 | + /** |
|
| 342 | + * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
| 343 | + * @param array $form Gravity Forms form array |
|
| 344 | + * @param string $entry_id Numeric ID of the entry that was updated |
|
| 345 | + */ |
|
| 346 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 347 | 347 | |
| 348 | - } else { |
|
| 349 | - do_action('gravityview_log_error', __METHOD__ . ': Submission is NOT valid.', $this->entry ); |
|
| 350 | - } |
|
| 348 | + } else { |
|
| 349 | + do_action('gravityview_log_error', __METHOD__ . ': Submission is NOT valid.', $this->entry ); |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - } // process_save |
|
| 352 | + } // process_save |
|
| 353 | 353 | |
| 354 | 354 | /** |
| 355 | 355 | * Delete the value of fields hidden by conditional logic when the entry is edited |
| 356 | - * |
|
| 357 | - * @uses GFFormsModel::update_lead_field_value() |
|
| 358 | - * |
|
| 359 | - * @since 1.17.4 |
|
| 360 | - * |
|
| 361 | - * @return void |
|
| 356 | + * |
|
| 357 | + * @uses GFFormsModel::update_lead_field_value() |
|
| 358 | + * |
|
| 359 | + * @since 1.17.4 |
|
| 360 | + * |
|
| 361 | + * @return void |
|
| 362 | + */ |
|
| 363 | + private function unset_hidden_field_values() { |
|
| 364 | + global $wpdb; |
|
| 365 | + |
|
| 366 | + $lead_detail_table = GFFormsModel::get_lead_details_table_name(); |
|
| 367 | + $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) ); |
|
| 368 | + |
|
| 369 | + foreach ( $this->entry as $input_id => $field_value ) { |
|
| 370 | + |
|
| 371 | + $field = RGFormsModel::get_field( $this->form, $input_id ); |
|
| 372 | + |
|
| 373 | + // Reset fields that are hidden |
|
| 374 | + // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic |
|
| 375 | + if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) { |
|
| 376 | + |
|
| 377 | + // List fields are stored as empty arrays when empty |
|
| 378 | + $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : ''; |
|
| 379 | + |
|
| 380 | + $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id ); |
|
| 381 | + |
|
| 382 | + GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value ); |
|
| 383 | + |
|
| 384 | + // Prevent the $_POST values of hidden fields from being used as default values when rendering the form |
|
| 385 | + // after submission |
|
| 386 | + $post_input_id = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 387 | + $_POST[ $post_input_id ] = ''; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Have GF handle file uploads |
|
| 394 | + * |
|
| 395 | + * Copy of code from GFFormDisplay::process_form() |
|
| 396 | + * |
|
| 397 | + * @param int $form_id |
|
| 398 | + */ |
|
| 399 | + private function process_save_process_files( $form_id ) { |
|
| 400 | + |
|
| 401 | + //Loading files that have been uploaded to temp folder |
|
| 402 | + $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
| 403 | + if ( ! is_array( $files ) ) { |
|
| 404 | + $files = array(); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
| 412 | + * Late validation done on self::custom_validation |
|
| 413 | + * |
|
| 414 | + * @param $plupload_init array Plupload settings |
|
| 415 | + * @param $form_id |
|
| 416 | + * @param $instance |
|
| 417 | + * @return mixed |
|
| 418 | + */ |
|
| 419 | + public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
| 420 | + if( ! $this->is_edit_entry() ) { |
|
| 421 | + return $plupload_init; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + $plupload_init['gf_vars']['max_files'] = 0; |
|
| 425 | + |
|
| 426 | + return $plupload_init; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Unset adminOnly and convert field input key to string |
|
| 432 | + * @return array $form |
|
| 433 | + */ |
|
| 434 | + private function form_prepare_for_save() { |
|
| 435 | + |
|
| 436 | + $form = $this->form; |
|
| 437 | + |
|
| 438 | + /** @var GF_Field $field */ |
|
| 439 | + foreach( $form['fields'] as $k => &$field ) { |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Remove the fields with calculation formulas before save to avoid conflicts with GF logic |
|
| 443 | + * @since 1.16.3 |
|
| 444 | + * @var GF_Field $field |
|
| 445 | + */ |
|
| 446 | + if( $field->has_calculation() ) { |
|
| 447 | + unset( $form['fields'][ $k ] ); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + $field->adminOnly = false; |
|
| 451 | + |
|
| 452 | + if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 453 | + foreach( $field->inputs as $key => $input ) { |
|
| 454 | + $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return $form; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + private function update_calculation_fields() { |
|
| 463 | + |
|
| 464 | + $form = self::$original_form; |
|
| 465 | + $update = false; |
|
| 466 | + |
|
| 467 | + // get the most up to date entry values |
|
| 468 | + $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 469 | + |
|
| 470 | + if( !empty( $this->fields_with_calculation ) ) { |
|
| 471 | + $update = true; |
|
| 472 | + foreach ( $this->fields_with_calculation as $calc_field ) { |
|
| 473 | + $inputs = $calc_field->get_entry_inputs(); |
|
| 474 | + if ( is_array( $inputs ) ) { |
|
| 475 | + foreach ( $inputs as $input ) { |
|
| 476 | + $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 477 | + $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 478 | + } |
|
| 479 | + } else { |
|
| 480 | + $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 481 | + $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + //saving total field as the last field of the form. |
|
| 488 | + if ( ! empty( $this->total_fields ) ) { |
|
| 489 | + $update = true; |
|
| 490 | + foreach ( $this->total_fields as $total_field ) { |
|
| 491 | + $input_name = 'input_' . str_replace( '.', '_', $total_field->id); |
|
| 492 | + $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry ); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if( $update ) { |
|
| 497 | + |
|
| 498 | + $return_entry = GFAPI::update_entry( $entry ); |
|
| 499 | + |
|
| 500 | + if( is_wp_error( $return_entry ) ) { |
|
| 501 | + do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry ); |
|
| 502 | + } else { |
|
| 503 | + do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' ); |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Handle updating the Post Image field |
|
| 510 | + * |
|
| 511 | + * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media |
|
| 512 | + * |
|
| 513 | + * @since 1.17 |
|
| 514 | + * |
|
| 515 | + * @uses GFFormsModel::media_handle_upload |
|
| 516 | + * @uses set_post_thumbnail |
|
| 517 | + * |
|
| 518 | + * @param array $form GF Form array |
|
| 519 | + * @param GF_Field $field GF Field |
|
| 520 | + * @param string $field_id Numeric ID of the field |
|
| 521 | + * @param string $value |
|
| 522 | + * @param array $entry GF Entry currently being edited |
|
| 523 | + * @param int $post_id ID of the Post being edited |
|
| 524 | + * |
|
| 525 | + * @return mixed|string |
|
| 526 | + */ |
|
| 527 | + private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) { |
|
| 528 | + |
|
| 529 | + $input_name = 'input_' . $field_id; |
|
| 530 | + |
|
| 531 | + if ( !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 532 | + |
|
| 533 | + // We have a new image |
|
| 534 | + |
|
| 535 | + $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
|
| 536 | + |
|
| 537 | + $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
|
| 538 | + $img_url = rgar( $ary, 0 ); |
|
| 539 | + |
|
| 540 | + $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
|
| 541 | + $img_caption = count( $ary ) > 2 ? $ary[2] : ''; |
|
| 542 | + $img_description = count( $ary ) > 3 ? $ary[3] : ''; |
|
| 543 | + |
|
| 544 | + $image_meta = array( |
|
| 545 | + 'post_excerpt' => $img_caption, |
|
| 546 | + 'post_content' => $img_description, |
|
| 547 | + ); |
|
| 548 | + |
|
| 549 | + //adding title only if it is not empty. It will default to the file name if it is not in the array |
|
| 550 | + if ( ! empty( $img_title ) ) { |
|
| 551 | + $image_meta['post_title'] = $img_title; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class. |
|
| 556 | + * Note: the method became public in GF 1.9.17.7, but we don't require that version yet. |
|
| 557 | + */ |
|
| 558 | + require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 559 | + $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta ); |
|
| 560 | + |
|
| 561 | + // is this field set as featured image? |
|
| 562 | + if ( $media_id && $field->postFeaturedImage ) { |
|
| 563 | + set_post_thumbnail( $post_id, $media_id ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 567 | + |
|
| 568 | + // Same image although the image title, caption or description might have changed |
|
| 569 | + |
|
| 570 | + $ary = array(); |
|
| 571 | + if( ! empty( $entry[ $field_id ] ) ) { |
|
| 572 | + $ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] ); |
|
| 573 | + } |
|
| 574 | + $img_url = rgar( $ary, 0 ); |
|
| 575 | + |
|
| 576 | + // is this really the same image or something went wrong ? |
|
| 577 | + if( $img_url === $_POST[ $input_name ] ) { |
|
| 578 | + |
|
| 579 | + $img_title = rgar( $value, $field_id .'.1' ); |
|
| 580 | + $img_caption = rgar( $value, $field_id .'.4' ); |
|
| 581 | + $img_description = rgar( $value, $field_id .'.7' ); |
|
| 582 | + |
|
| 583 | + $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; |
|
| 584 | + |
|
| 585 | + if ( $field->postFeaturedImage ) { |
|
| 586 | + |
|
| 587 | + $image_meta = array( |
|
| 588 | + 'ID' => get_post_thumbnail_id( $post_id ), |
|
| 589 | + 'post_title' => $img_title, |
|
| 590 | + 'post_excerpt' => $img_caption, |
|
| 591 | + 'post_content' => $img_description, |
|
| 592 | + ); |
|
| 593 | + |
|
| 594 | + // update image title, caption or description |
|
| 595 | + wp_update_post( $image_meta ); |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + } else { |
|
| 600 | + |
|
| 601 | + // if we get here, image was removed or not set. |
|
| 602 | + $value = ''; |
|
| 603 | + |
|
| 604 | + if ( $field->postFeaturedImage ) { |
|
| 605 | + delete_post_thumbnail( $post_id ); |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + return $value; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
| 614 | + * |
|
| 615 | + * @param array $form Gravity Forms form |
|
| 616 | + * |
|
| 617 | + * @return void |
|
| 362 | 618 | */ |
| 363 | - private function unset_hidden_field_values() { |
|
| 364 | - global $wpdb; |
|
| 365 | - |
|
| 366 | - $lead_detail_table = GFFormsModel::get_lead_details_table_name(); |
|
| 367 | - $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) ); |
|
| 368 | - |
|
| 369 | - foreach ( $this->entry as $input_id => $field_value ) { |
|
| 370 | - |
|
| 371 | - $field = RGFormsModel::get_field( $this->form, $input_id ); |
|
| 372 | - |
|
| 373 | - // Reset fields that are hidden |
|
| 374 | - // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic |
|
| 375 | - if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) { |
|
| 376 | - |
|
| 377 | - // List fields are stored as empty arrays when empty |
|
| 378 | - $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : ''; |
|
| 379 | - |
|
| 380 | - $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id ); |
|
| 381 | - |
|
| 382 | - GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value ); |
|
| 383 | - |
|
| 384 | - // Prevent the $_POST values of hidden fields from being used as default values when rendering the form |
|
| 385 | - // after submission |
|
| 386 | - $post_input_id = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 387 | - $_POST[ $post_input_id ] = ''; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Have GF handle file uploads |
|
| 394 | - * |
|
| 395 | - * Copy of code from GFFormDisplay::process_form() |
|
| 396 | - * |
|
| 397 | - * @param int $form_id |
|
| 398 | - */ |
|
| 399 | - private function process_save_process_files( $form_id ) { |
|
| 400 | - |
|
| 401 | - //Loading files that have been uploaded to temp folder |
|
| 402 | - $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
| 403 | - if ( ! is_array( $files ) ) { |
|
| 404 | - $files = array(); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
| 412 | - * Late validation done on self::custom_validation |
|
| 413 | - * |
|
| 414 | - * @param $plupload_init array Plupload settings |
|
| 415 | - * @param $form_id |
|
| 416 | - * @param $instance |
|
| 417 | - * @return mixed |
|
| 418 | - */ |
|
| 419 | - public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
| 420 | - if( ! $this->is_edit_entry() ) { |
|
| 421 | - return $plupload_init; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - $plupload_init['gf_vars']['max_files'] = 0; |
|
| 425 | - |
|
| 426 | - return $plupload_init; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Unset adminOnly and convert field input key to string |
|
| 432 | - * @return array $form |
|
| 433 | - */ |
|
| 434 | - private function form_prepare_for_save() { |
|
| 435 | - |
|
| 436 | - $form = $this->form; |
|
| 437 | - |
|
| 438 | - /** @var GF_Field $field */ |
|
| 439 | - foreach( $form['fields'] as $k => &$field ) { |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Remove the fields with calculation formulas before save to avoid conflicts with GF logic |
|
| 443 | - * @since 1.16.3 |
|
| 444 | - * @var GF_Field $field |
|
| 445 | - */ |
|
| 446 | - if( $field->has_calculation() ) { |
|
| 447 | - unset( $form['fields'][ $k ] ); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - $field->adminOnly = false; |
|
| 451 | - |
|
| 452 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 453 | - foreach( $field->inputs as $key => $input ) { |
|
| 454 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - return $form; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - private function update_calculation_fields() { |
|
| 463 | - |
|
| 464 | - $form = self::$original_form; |
|
| 465 | - $update = false; |
|
| 466 | - |
|
| 467 | - // get the most up to date entry values |
|
| 468 | - $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 469 | - |
|
| 470 | - if( !empty( $this->fields_with_calculation ) ) { |
|
| 471 | - $update = true; |
|
| 472 | - foreach ( $this->fields_with_calculation as $calc_field ) { |
|
| 473 | - $inputs = $calc_field->get_entry_inputs(); |
|
| 474 | - if ( is_array( $inputs ) ) { |
|
| 475 | - foreach ( $inputs as $input ) { |
|
| 476 | - $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 477 | - $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 478 | - } |
|
| 479 | - } else { |
|
| 480 | - $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 481 | - $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - //saving total field as the last field of the form. |
|
| 488 | - if ( ! empty( $this->total_fields ) ) { |
|
| 489 | - $update = true; |
|
| 490 | - foreach ( $this->total_fields as $total_field ) { |
|
| 491 | - $input_name = 'input_' . str_replace( '.', '_', $total_field->id); |
|
| 492 | - $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry ); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if( $update ) { |
|
| 497 | - |
|
| 498 | - $return_entry = GFAPI::update_entry( $entry ); |
|
| 499 | - |
|
| 500 | - if( is_wp_error( $return_entry ) ) { |
|
| 501 | - do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry ); |
|
| 502 | - } else { |
|
| 503 | - do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' ); |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Handle updating the Post Image field |
|
| 510 | - * |
|
| 511 | - * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media |
|
| 512 | - * |
|
| 513 | - * @since 1.17 |
|
| 514 | - * |
|
| 515 | - * @uses GFFormsModel::media_handle_upload |
|
| 516 | - * @uses set_post_thumbnail |
|
| 517 | - * |
|
| 518 | - * @param array $form GF Form array |
|
| 519 | - * @param GF_Field $field GF Field |
|
| 520 | - * @param string $field_id Numeric ID of the field |
|
| 521 | - * @param string $value |
|
| 522 | - * @param array $entry GF Entry currently being edited |
|
| 523 | - * @param int $post_id ID of the Post being edited |
|
| 524 | - * |
|
| 525 | - * @return mixed|string |
|
| 526 | - */ |
|
| 527 | - private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) { |
|
| 528 | - |
|
| 529 | - $input_name = 'input_' . $field_id; |
|
| 530 | - |
|
| 531 | - if ( !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 532 | - |
|
| 533 | - // We have a new image |
|
| 534 | - |
|
| 535 | - $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
|
| 536 | - |
|
| 537 | - $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
|
| 538 | - $img_url = rgar( $ary, 0 ); |
|
| 539 | - |
|
| 540 | - $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
|
| 541 | - $img_caption = count( $ary ) > 2 ? $ary[2] : ''; |
|
| 542 | - $img_description = count( $ary ) > 3 ? $ary[3] : ''; |
|
| 543 | - |
|
| 544 | - $image_meta = array( |
|
| 545 | - 'post_excerpt' => $img_caption, |
|
| 546 | - 'post_content' => $img_description, |
|
| 547 | - ); |
|
| 548 | - |
|
| 549 | - //adding title only if it is not empty. It will default to the file name if it is not in the array |
|
| 550 | - if ( ! empty( $img_title ) ) { |
|
| 551 | - $image_meta['post_title'] = $img_title; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class. |
|
| 556 | - * Note: the method became public in GF 1.9.17.7, but we don't require that version yet. |
|
| 557 | - */ |
|
| 558 | - require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 559 | - $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta ); |
|
| 560 | - |
|
| 561 | - // is this field set as featured image? |
|
| 562 | - if ( $media_id && $field->postFeaturedImage ) { |
|
| 563 | - set_post_thumbnail( $post_id, $media_id ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 567 | - |
|
| 568 | - // Same image although the image title, caption or description might have changed |
|
| 569 | - |
|
| 570 | - $ary = array(); |
|
| 571 | - if( ! empty( $entry[ $field_id ] ) ) { |
|
| 572 | - $ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] ); |
|
| 573 | - } |
|
| 574 | - $img_url = rgar( $ary, 0 ); |
|
| 575 | - |
|
| 576 | - // is this really the same image or something went wrong ? |
|
| 577 | - if( $img_url === $_POST[ $input_name ] ) { |
|
| 578 | - |
|
| 579 | - $img_title = rgar( $value, $field_id .'.1' ); |
|
| 580 | - $img_caption = rgar( $value, $field_id .'.4' ); |
|
| 581 | - $img_description = rgar( $value, $field_id .'.7' ); |
|
| 582 | - |
|
| 583 | - $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; |
|
| 584 | - |
|
| 585 | - if ( $field->postFeaturedImage ) { |
|
| 586 | - |
|
| 587 | - $image_meta = array( |
|
| 588 | - 'ID' => get_post_thumbnail_id( $post_id ), |
|
| 589 | - 'post_title' => $img_title, |
|
| 590 | - 'post_excerpt' => $img_caption, |
|
| 591 | - 'post_content' => $img_description, |
|
| 592 | - ); |
|
| 593 | - |
|
| 594 | - // update image title, caption or description |
|
| 595 | - wp_update_post( $image_meta ); |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - } else { |
|
| 600 | - |
|
| 601 | - // if we get here, image was removed or not set. |
|
| 602 | - $value = ''; |
|
| 603 | - |
|
| 604 | - if ( $field->postFeaturedImage ) { |
|
| 605 | - delete_post_thumbnail( $post_id ); |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - return $value; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
| 614 | - * |
|
| 615 | - * @param array $form Gravity Forms form |
|
| 616 | - * |
|
| 617 | - * @return void |
|
| 618 | - */ |
|
| 619 | - private function maybe_update_post_fields( $form ) { |
|
| 619 | + private function maybe_update_post_fields( $form ) { |
|
| 620 | 620 | |
| 621 | - if( empty( $this->entry['post_id'] ) ) { |
|
| 622 | - do_action( 'gravityview_log_debug', __METHOD__ . ': This entry has no post fields. Continuing...' ); |
|
| 623 | - return; |
|
| 624 | - } |
|
| 621 | + if( empty( $this->entry['post_id'] ) ) { |
|
| 622 | + do_action( 'gravityview_log_debug', __METHOD__ . ': This entry has no post fields. Continuing...' ); |
|
| 623 | + return; |
|
| 624 | + } |
|
| 625 | 625 | |
| 626 | - $post_id = $this->entry['post_id']; |
|
| 626 | + $post_id = $this->entry['post_id']; |
|
| 627 | 627 | |
| 628 | - // Security check |
|
| 629 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 630 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 631 | - return; |
|
| 632 | - } |
|
| 628 | + // Security check |
|
| 629 | + if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 630 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 631 | + return; |
|
| 632 | + } |
|
| 633 | 633 | |
| 634 | - $update_entry = false; |
|
| 634 | + $update_entry = false; |
|
| 635 | 635 | |
| 636 | - $updated_post = $original_post = get_post( $post_id ); |
|
| 636 | + $updated_post = $original_post = get_post( $post_id ); |
|
| 637 | 637 | |
| 638 | - foreach ( $this->entry as $field_id => $value ) { |
|
| 638 | + foreach ( $this->entry as $field_id => $value ) { |
|
| 639 | 639 | |
| 640 | - $field = RGFormsModel::get_field( $form, $field_id ); |
|
| 640 | + $field = RGFormsModel::get_field( $form, $field_id ); |
|
| 641 | 641 | |
| 642 | - if( ! $field ) { |
|
| 643 | - continue; |
|
| 644 | - } |
|
| 642 | + if( ! $field ) { |
|
| 643 | + continue; |
|
| 644 | + } |
|
| 645 | 645 | |
| 646 | - if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) { |
|
| 646 | + if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) { |
|
| 647 | 647 | |
| 648 | - // Get the value of the field, including $_POSTed value |
|
| 649 | - $value = RGFormsModel::get_field_value( $field ); |
|
| 648 | + // Get the value of the field, including $_POSTed value |
|
| 649 | + $value = RGFormsModel::get_field_value( $field ); |
|
| 650 | 650 | |
| 651 | - // Use temporary entry variable, to make values available to fill_post_template() and update_post_image() |
|
| 652 | - $entry_tmp = $this->entry; |
|
| 653 | - $entry_tmp["{$field_id}"] = $value; |
|
| 651 | + // Use temporary entry variable, to make values available to fill_post_template() and update_post_image() |
|
| 652 | + $entry_tmp = $this->entry; |
|
| 653 | + $entry_tmp["{$field_id}"] = $value; |
|
| 654 | 654 | |
| 655 | - switch( $field->type ) { |
|
| 655 | + switch( $field->type ) { |
|
| 656 | 656 | |
| 657 | - case 'post_title': |
|
| 658 | - $post_title = $value; |
|
| 659 | - if( rgar( $form, 'postTitleTemplateEnabled' ) ) { |
|
| 660 | - $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp ); |
|
| 661 | - } |
|
| 662 | - $updated_post->post_title = $post_title; |
|
| 663 | - $updated_post->post_name = $post_title; |
|
| 664 | - unset( $post_title ); |
|
| 665 | - break; |
|
| 657 | + case 'post_title': |
|
| 658 | + $post_title = $value; |
|
| 659 | + if( rgar( $form, 'postTitleTemplateEnabled' ) ) { |
|
| 660 | + $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp ); |
|
| 661 | + } |
|
| 662 | + $updated_post->post_title = $post_title; |
|
| 663 | + $updated_post->post_name = $post_title; |
|
| 664 | + unset( $post_title ); |
|
| 665 | + break; |
|
| 666 | 666 | |
| 667 | - case 'post_content': |
|
| 668 | - $post_content = $value; |
|
| 669 | - if( rgar( $form, 'postContentTemplateEnabled' ) ) { |
|
| 670 | - $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true ); |
|
| 671 | - } |
|
| 672 | - $updated_post->post_content = $post_content; |
|
| 673 | - unset( $post_content ); |
|
| 674 | - break; |
|
| 675 | - case 'post_excerpt': |
|
| 676 | - $updated_post->post_excerpt = $value; |
|
| 677 | - break; |
|
| 678 | - case 'post_tags': |
|
| 679 | - wp_set_post_tags( $post_id, $value, false ); |
|
| 680 | - break; |
|
| 681 | - case 'post_category': |
|
| 682 | - break; |
|
| 683 | - case 'post_custom_field': |
|
| 684 | - if( ! empty( $field->customFieldTemplateEnabled ) ) { |
|
| 685 | - $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true ); |
|
| 686 | - } |
|
| 667 | + case 'post_content': |
|
| 668 | + $post_content = $value; |
|
| 669 | + if( rgar( $form, 'postContentTemplateEnabled' ) ) { |
|
| 670 | + $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true ); |
|
| 671 | + } |
|
| 672 | + $updated_post->post_content = $post_content; |
|
| 673 | + unset( $post_content ); |
|
| 674 | + break; |
|
| 675 | + case 'post_excerpt': |
|
| 676 | + $updated_post->post_excerpt = $value; |
|
| 677 | + break; |
|
| 678 | + case 'post_tags': |
|
| 679 | + wp_set_post_tags( $post_id, $value, false ); |
|
| 680 | + break; |
|
| 681 | + case 'post_category': |
|
| 682 | + break; |
|
| 683 | + case 'post_custom_field': |
|
| 684 | + if( ! empty( $field->customFieldTemplateEnabled ) ) { |
|
| 685 | + $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true ); |
|
| 686 | + } |
|
| 687 | 687 | |
| 688 | - if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) { |
|
| 689 | - $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 690 | - } |
|
| 688 | + if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) { |
|
| 689 | + $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 690 | + } |
|
| 691 | 691 | |
| 692 | - update_post_meta( $post_id, $field->postCustomFieldName, $value ); |
|
| 692 | + update_post_meta( $post_id, $field->postCustomFieldName, $value ); |
|
| 693 | 693 | |
| 694 | - break; |
|
| 694 | + break; |
|
| 695 | 695 | |
| 696 | - case 'post_image': |
|
| 697 | - $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id ); |
|
| 698 | - break; |
|
| 696 | + case 'post_image': |
|
| 697 | + $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id ); |
|
| 698 | + break; |
|
| 699 | 699 | |
| 700 | - } |
|
| 700 | + } |
|
| 701 | 701 | |
| 702 | - // update entry after |
|
| 703 | - $this->entry["{$field_id}"] = $value; |
|
| 702 | + // update entry after |
|
| 703 | + $this->entry["{$field_id}"] = $value; |
|
| 704 | 704 | |
| 705 | - $update_entry = true; |
|
| 705 | + $update_entry = true; |
|
| 706 | 706 | |
| 707 | - unset( $entry_tmp ); |
|
| 708 | - } |
|
| 707 | + unset( $entry_tmp ); |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | - } |
|
| 710 | + } |
|
| 711 | 711 | |
| 712 | - if( $update_entry ) { |
|
| 712 | + if( $update_entry ) { |
|
| 713 | 713 | |
| 714 | - $return_entry = GFAPI::update_entry( $this->entry ); |
|
| 714 | + $return_entry = GFAPI::update_entry( $this->entry ); |
|
| 715 | 715 | |
| 716 | - if( is_wp_error( $return_entry ) ) { |
|
| 717 | - do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) ); |
|
| 718 | - } else { |
|
| 719 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 720 | - } |
|
| 716 | + if( is_wp_error( $return_entry ) ) { |
|
| 717 | + do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) ); |
|
| 718 | + } else { |
|
| 719 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | - } |
|
| 722 | + } |
|
| 723 | 723 | |
| 724 | - $return_post = wp_update_post( $updated_post, true ); |
|
| 724 | + $return_post = wp_update_post( $updated_post, true ); |
|
| 725 | 725 | |
| 726 | - if( is_wp_error( $return_post ) ) { |
|
| 727 | - $return_post->add_data( $updated_post, '$updated_post' ); |
|
| 728 | - do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) ); |
|
| 729 | - } else { |
|
| 730 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); |
|
| 731 | - } |
|
| 732 | - } |
|
| 726 | + if( is_wp_error( $return_post ) ) { |
|
| 727 | + $return_post->add_data( $updated_post, '$updated_post' ); |
|
| 728 | + do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) ); |
|
| 729 | + } else { |
|
| 730 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | 733 | |
| 734 | 734 | /** |
| 735 | - * Is the field stored in a JSON-encoded manner? |
|
| 736 | - * |
|
| 735 | + * Is the field stored in a JSON-encoded manner? |
|
| 736 | + * |
|
| 737 | 737 | * @param GF_Field $field |
| 738 | 738 | * |
| 739 | 739 | * @return bool True: stored in DB json_encode()'d; False: not encoded |
| 740 | 740 | */ |
| 741 | - private function is_field_json_encoded( $field ) { |
|
| 741 | + private function is_field_json_encoded( $field ) { |
|
| 742 | 742 | |
| 743 | - $json_encoded = false; |
|
| 743 | + $json_encoded = false; |
|
| 744 | 744 | |
| 745 | - $input_type = RGFormsModel::get_input_type( $field ); |
|
| 745 | + $input_type = RGFormsModel::get_input_type( $field ); |
|
| 746 | 746 | |
| 747 | - // Only certain custom field types are supported |
|
| 748 | - switch( $input_type ) { |
|
| 749 | - case 'fileupload': |
|
| 750 | - case 'list': |
|
| 751 | - case 'multiselect': |
|
| 752 | - $json_encoded = true; |
|
| 753 | - break; |
|
| 754 | - } |
|
| 747 | + // Only certain custom field types are supported |
|
| 748 | + switch( $input_type ) { |
|
| 749 | + case 'fileupload': |
|
| 750 | + case 'list': |
|
| 751 | + case 'multiselect': |
|
| 752 | + $json_encoded = true; |
|
| 753 | + break; |
|
| 754 | + } |
|
| 755 | 755 | |
| 756 | - return $json_encoded; |
|
| 757 | - } |
|
| 756 | + return $json_encoded; |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - /** |
|
| 760 | - * Convert a field content template into prepared output |
|
| 761 | - * |
|
| 762 | - * @uses GravityView_GFFormsModel::get_post_field_images() |
|
| 763 | - * |
|
| 764 | - * @since 1.17 |
|
| 765 | - * |
|
| 766 | - * @param string $template The content template for the field |
|
| 767 | - * @param array $form Gravity Forms form |
|
| 768 | - * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields |
|
| 769 | - * |
|
| 770 | - * @return mixed|string|void |
|
| 771 | - */ |
|
| 772 | - private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) { |
|
| 759 | + /** |
|
| 760 | + * Convert a field content template into prepared output |
|
| 761 | + * |
|
| 762 | + * @uses GravityView_GFFormsModel::get_post_field_images() |
|
| 763 | + * |
|
| 764 | + * @since 1.17 |
|
| 765 | + * |
|
| 766 | + * @param string $template The content template for the field |
|
| 767 | + * @param array $form Gravity Forms form |
|
| 768 | + * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields |
|
| 769 | + * |
|
| 770 | + * @return mixed|string|void |
|
| 771 | + */ |
|
| 772 | + private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) { |
|
| 773 | 773 | |
| 774 | - require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 774 | + require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 775 | 775 | |
| 776 | - $post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry ); |
|
| 776 | + $post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry ); |
|
| 777 | 777 | |
| 778 | - //replacing post image variables |
|
| 779 | - $output = GFCommon::replace_variables_post_image( $template, $post_images, $entry ); |
|
| 778 | + //replacing post image variables |
|
| 779 | + $output = GFCommon::replace_variables_post_image( $template, $post_images, $entry ); |
|
| 780 | 780 | |
| 781 | - //replacing all other variables |
|
| 782 | - $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false ); |
|
| 781 | + //replacing all other variables |
|
| 782 | + $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false ); |
|
| 783 | 783 | |
| 784 | - // replace conditional shortcodes |
|
| 785 | - if( $do_shortcode ) { |
|
| 786 | - $output = do_shortcode( $output ); |
|
| 787 | - } |
|
| 784 | + // replace conditional shortcodes |
|
| 785 | + if( $do_shortcode ) { |
|
| 786 | + $output = do_shortcode( $output ); |
|
| 787 | + } |
|
| 788 | 788 | |
| 789 | - return $output; |
|
| 790 | - } |
|
| 789 | + return $output; |
|
| 790 | + } |
|
| 791 | 791 | |
| 792 | 792 | |
| 793 | - /** |
|
| 794 | - * Perform actions normally performed after updating a lead |
|
| 795 | - * |
|
| 796 | - * @since 1.8 |
|
| 797 | - * |
|
| 798 | - * @see GFEntryDetail::lead_detail_page() |
|
| 799 | - * |
|
| 800 | - * @return void |
|
| 801 | - */ |
|
| 802 | - private function after_update() { |
|
| 793 | + /** |
|
| 794 | + * Perform actions normally performed after updating a lead |
|
| 795 | + * |
|
| 796 | + * @since 1.8 |
|
| 797 | + * |
|
| 798 | + * @see GFEntryDetail::lead_detail_page() |
|
| 799 | + * |
|
| 800 | + * @return void |
|
| 801 | + */ |
|
| 802 | + private function after_update() { |
|
| 803 | 803 | |
| 804 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry ); |
|
| 805 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 804 | + do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry ); |
|
| 805 | + do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 806 | 806 | |
| 807 | - // Re-define the entry now that we've updated it. |
|
| 808 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 807 | + // Re-define the entry now that we've updated it. |
|
| 808 | + $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 809 | 809 | |
| 810 | - $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
| 810 | + $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
| 811 | 811 | |
| 812 | - // We need to clear the cache because Gravity Forms caches the field values, which |
|
| 813 | - // we have just updated. |
|
| 814 | - foreach ($this->form['fields'] as $key => $field) { |
|
| 815 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 816 | - } |
|
| 812 | + // We need to clear the cache because Gravity Forms caches the field values, which |
|
| 813 | + // we have just updated. |
|
| 814 | + foreach ($this->form['fields'] as $key => $field) { |
|
| 815 | + GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 816 | + } |
|
| 817 | 817 | |
| 818 | - $this->entry = $entry; |
|
| 819 | - } |
|
| 818 | + $this->entry = $entry; |
|
| 819 | + } |
|
| 820 | 820 | |
| 821 | 821 | |
| 822 | - /** |
|
| 823 | - * Display the Edit Entry form |
|
| 824 | - * |
|
| 825 | - * @return void |
|
| 826 | - */ |
|
| 827 | - public function edit_entry_form() { |
|
| 822 | + /** |
|
| 823 | + * Display the Edit Entry form |
|
| 824 | + * |
|
| 825 | + * @return void |
|
| 826 | + */ |
|
| 827 | + public function edit_entry_form() { |
|
| 828 | 828 | |
| 829 | - ?> |
|
| 829 | + ?> |
|
| 830 | 830 | |
| 831 | 831 | <div class="gv-edit-entry-wrapper"><?php |
| 832 | 832 | |
| 833 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 833 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 834 | 834 | |
| 835 | - /** |
|
| 836 | - * Fixes weird wpautop() issue |
|
| 837 | - * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
| 838 | - */ |
|
| 839 | - echo gravityview_strip_whitespace( $javascript ); |
|
| 835 | + /** |
|
| 836 | + * Fixes weird wpautop() issue |
|
| 837 | + * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
| 838 | + */ |
|
| 839 | + echo gravityview_strip_whitespace( $javascript ); |
|
| 840 | 840 | |
| 841 | - ?><h2 class="gv-edit-entry-title"> |
|
| 841 | + ?><h2 class="gv-edit-entry-title"> |
|
| 842 | 842 | <span><?php |
| 843 | 843 | |
| 844 | - /** |
|
| 845 | - * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 846 | - * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 847 | - * @param GravityView_Edit_Entry_Render $this This object |
|
| 848 | - */ |
|
| 849 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 844 | + /** |
|
| 845 | + * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 846 | + * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 847 | + * @param GravityView_Edit_Entry_Render $this This object |
|
| 848 | + */ |
|
| 849 | + $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 850 | 850 | |
| 851 | - echo esc_attr( $edit_entry_title ); |
|
| 852 | - ?></span> |
|
| 851 | + echo esc_attr( $edit_entry_title ); |
|
| 852 | + ?></span> |
|
| 853 | 853 | </h2> |
| 854 | 854 | |
| 855 | 855 | <?php $this->maybe_print_message(); ?> |
@@ -860,14 +860,14 @@ discard block |
||
| 860 | 860 | |
| 861 | 861 | <?php |
| 862 | 862 | |
| 863 | - wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
| 863 | + wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
| 864 | 864 | |
| 865 | - wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
| 865 | + wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
| 866 | 866 | |
| 867 | - // Print the actual form HTML |
|
| 868 | - $this->render_edit_form(); |
|
| 867 | + // Print the actual form HTML |
|
| 868 | + $this->render_edit_form(); |
|
| 869 | 869 | |
| 870 | - ?> |
|
| 870 | + ?> |
|
| 871 | 871 | </form> |
| 872 | 872 | |
| 873 | 873 | <script> |
@@ -879,1154 +879,1154 @@ discard block |
||
| 879 | 879 | </div> |
| 880 | 880 | |
| 881 | 881 | <?php |
| 882 | - } |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * Display success or error message if the form has been submitted |
|
| 886 | - * |
|
| 887 | - * @uses GVCommon::generate_notice |
|
| 888 | - * |
|
| 889 | - * @since 1.16.2.2 |
|
| 890 | - * |
|
| 891 | - * @return void |
|
| 892 | - */ |
|
| 893 | - private function maybe_print_message() { |
|
| 894 | - |
|
| 895 | - if( rgpost('action') === 'update' ) { |
|
| 896 | - |
|
| 897 | - $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
| 898 | - |
|
| 899 | - if( ! $this->is_valid ){ |
|
| 900 | - |
|
| 901 | - // Keeping this compatible with Gravity Forms. |
|
| 902 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 903 | - $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 904 | - |
|
| 905 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 906 | - |
|
| 907 | - } else { |
|
| 908 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
| 912 | - * @since 1.5.4 |
|
| 913 | - * @param string $entry_updated_message Existing message |
|
| 914 | - * @param int $view_id View ID |
|
| 915 | - * @param array $entry Gravity Forms entry array |
|
| 916 | - * @param string $back_link URL to return to the original entry. @since 1.6 |
|
| 917 | - */ |
|
| 918 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 919 | - |
|
| 920 | - echo GVCommon::generate_notice( $message ); |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - } |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * Display the Edit Entry form in the original Gravity Forms format |
|
| 928 | - * |
|
| 929 | - * @since 1.9 |
|
| 930 | - * |
|
| 931 | - * @return void |
|
| 932 | - */ |
|
| 933 | - private function render_edit_form() { |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form |
|
| 937 | - * @since 1.17 |
|
| 938 | - * @param GravityView_Edit_Entry_Render $this |
|
| 939 | - */ |
|
| 940 | - do_action( 'gravityview/edit-entry/render/before', $this ); |
|
| 941 | - |
|
| 942 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 943 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 944 | - add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 945 | - |
|
| 946 | - add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); |
|
| 947 | - add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
| 948 | - |
|
| 949 | - // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
| 950 | - unset( $_GET['page'] ); |
|
| 951 | - |
|
| 952 | - // TODO: Verify multiple-page forms |
|
| 953 | - // TODO: Product fields are not editable |
|
| 954 | - |
|
| 955 | - ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic |
|
| 956 | - |
|
| 957 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 958 | - |
|
| 959 | - ob_get_clean(); |
|
| 960 | - |
|
| 961 | - remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 962 | - remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 963 | - remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 964 | - remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); |
|
| 965 | - remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
| 966 | - |
|
| 967 | - echo $html; |
|
| 968 | - |
|
| 969 | - /** |
|
| 970 | - * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form |
|
| 971 | - * @since 1.17 |
|
| 972 | - * @param GravityView_Edit_Entry_Render $this |
|
| 973 | - */ |
|
| 974 | - do_action( 'gravityview/edit-entry/render/after', $this ); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
| 979 | - * @since 1.8 |
|
| 980 | - * @return string |
|
| 981 | - */ |
|
| 982 | - public function render_form_buttons() { |
|
| 983 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
| 989 | - * |
|
| 990 | - * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
| 991 | - * |
|
| 992 | - * @param array $form |
|
| 993 | - * @param boolean $ajax Whether in AJAX mode |
|
| 994 | - * @param array|string $field_values Passed parameters to the form |
|
| 995 | - * |
|
| 996 | - * @since 1.9 |
|
| 997 | - * |
|
| 998 | - * @return array Modified form array |
|
| 999 | - */ |
|
| 1000 | - public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
| 1001 | - |
|
| 1002 | - // In case we have validated the form, use it to inject the validation results into the form render |
|
| 1003 | - if( isset( $this->form_after_validation ) ) { |
|
| 1004 | - $form = $this->form_after_validation; |
|
| 1005 | - } else { |
|
| 1006 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - $form = $this->filter_conditional_logic( $form ); |
|
| 1010 | - |
|
| 1011 | - $form = $this->prefill_conditional_logic( $form ); |
|
| 1012 | - |
|
| 1013 | - // for now we don't support Save and Continue feature. |
|
| 1014 | - if( ! self::$supports_save_and_continue ) { |
|
| 1015 | - unset( $form['save'] ); |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - return $form; |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * When displaying a field, check if it's a Post Field, and if so, make sure the post exists and current user has edit rights. |
|
| 1023 | - * |
|
| 1024 | - * @since 1.16.2.2 |
|
| 1025 | - * |
|
| 1026 | - * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 1027 | - * @param GF_Field $field |
|
| 1028 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 1029 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 1030 | - * @param int $form_id Form ID |
|
| 1031 | - * |
|
| 1032 | - * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next) |
|
| 1033 | - */ |
|
| 1034 | - public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 1035 | - |
|
| 1036 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 1037 | - |
|
| 1038 | - $message = null; |
|
| 1039 | - |
|
| 1040 | - // First, make sure they have the capability to edit the post. |
|
| 1041 | - if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post |
|
| 1045 | - * @param string $message The existing "You don't have permission..." text |
|
| 1046 | - */ |
|
| 1047 | - $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); |
|
| 1048 | - |
|
| 1049 | - } elseif( null === get_post( $this->entry['post_id'] ) ) { |
|
| 1050 | - /** |
|
| 1051 | - * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists |
|
| 1052 | - * @param string $message The existing "This field is not editable; the post no longer exists." text |
|
| 1053 | - */ |
|
| 1054 | - $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - if( $message ) { |
|
| 1058 | - $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - return $field_content; |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * |
|
| 1067 | - * Fill-in the saved values into the form inputs |
|
| 1068 | - * |
|
| 1069 | - * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 1070 | - * @param GF_Field $field |
|
| 1071 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 1072 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 1073 | - * @param int $form_id Form ID |
|
| 1074 | - * |
|
| 1075 | - * @return mixed |
|
| 1076 | - */ |
|
| 1077 | - public function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 1078 | - |
|
| 1079 | - $gv_field = GravityView_Fields::get_associated_field( $field ); |
|
| 1080 | - |
|
| 1081 | - // If the form has been submitted, then we don't need to pre-fill the values, |
|
| 1082 | - // Except for fileupload type and when a field input is overridden- run always!! |
|
| 1083 | - if( |
|
| 1084 | - ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 1085 | - && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) |
|
| 1086 | - || ! empty( $field_content ) |
|
| 1087 | - || in_array( $field->type, array( 'honeypot' ) ) |
|
| 1088 | - || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
| 1089 | - ) { |
|
| 1090 | - return $field_content; |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - // Turn on Admin-style display for file upload fields only |
|
| 1094 | - if( 'fileupload' === $field->type ) { |
|
| 1095 | - $_GET['page'] = 'gf_entries'; |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
| 1099 | - $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
| 1100 | - |
|
| 1101 | - // add categories as choices for Post Category field |
|
| 1102 | - if ( 'post_category' === $field->type ) { |
|
| 1103 | - $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - $field_value = $this->get_field_value( $field ); |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 1110 | - * @since 1.11 |
|
| 1111 | - * @param mixed $field_value field value used to populate the input |
|
| 1112 | - * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 1113 | - */ |
|
| 1114 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
| 1115 | - |
|
| 1116 | - /** |
|
| 1117 | - * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type |
|
| 1118 | - * @since 1.17 |
|
| 1119 | - * @param mixed $field_value field value used to populate the input |
|
| 1120 | - * @param GF_Field $field Gravity Forms field object |
|
| 1121 | - */ |
|
| 1122 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field ); |
|
| 1123 | - |
|
| 1124 | - // Prevent any PHP warnings, like undefined index |
|
| 1125 | - ob_start(); |
|
| 1126 | - |
|
| 1127 | - /** @var GravityView_Field $gv_field */ |
|
| 1128 | - if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1129 | - $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
|
| 1130 | - } else { |
|
| 1131 | - $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - |
|
| 1135 | - // If there was output, it's an error |
|
| 1136 | - $warnings = ob_get_clean(); |
|
| 1137 | - |
|
| 1138 | - if( !empty( $warnings ) ) { |
|
| 1139 | - do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - /** |
|
| 1143 | - * Unset hack $_GET['page'] = 'gf_entries' |
|
| 1144 | - * We need the fileupload html field to render with the proper id |
|
| 1145 | - * ( <li id="field_80_16" ... > ) |
|
| 1146 | - */ |
|
| 1147 | - unset( $_GET['page'] ); |
|
| 1148 | - |
|
| 1149 | - return $return; |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * Modify the value for the current field input |
|
| 1154 | - * |
|
| 1155 | - * @param GF_Field $field |
|
| 1156 | - * |
|
| 1157 | - * @return array|mixed|string|void |
|
| 1158 | - */ |
|
| 1159 | - private function get_field_value( $field ) { |
|
| 1160 | - |
|
| 1161 | - /** |
|
| 1162 | - * @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. |
|
| 1163 | - * @param boolean True: override saved values; False: don't override (default) |
|
| 1164 | - * @param $field GF_Field object Gravity Forms field object |
|
| 1165 | - * @since 1.13 |
|
| 1166 | - */ |
|
| 1167 | - $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
| 1168 | - |
|
| 1169 | - // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
| 1170 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1171 | - |
|
| 1172 | - $field_value = array(); |
|
| 1173 | - |
|
| 1174 | - // only accept pre-populated values if the field doesn't have any choice selected. |
|
| 1175 | - $allow_pre_populated = $field->allowsPrepopulate; |
|
| 1176 | - |
|
| 1177 | - foreach ( (array)$field->inputs as $input ) { |
|
| 1178 | - |
|
| 1179 | - $input_id = strval( $input['id'] ); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * Display success or error message if the form has been submitted |
|
| 886 | + * |
|
| 887 | + * @uses GVCommon::generate_notice |
|
| 888 | + * |
|
| 889 | + * @since 1.16.2.2 |
|
| 890 | + * |
|
| 891 | + * @return void |
|
| 892 | + */ |
|
| 893 | + private function maybe_print_message() { |
|
| 894 | + |
|
| 895 | + if( rgpost('action') === 'update' ) { |
|
| 896 | + |
|
| 897 | + $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
| 898 | + |
|
| 899 | + if( ! $this->is_valid ){ |
|
| 900 | + |
|
| 901 | + // Keeping this compatible with Gravity Forms. |
|
| 902 | + $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 903 | + $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 904 | + |
|
| 905 | + echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 906 | + |
|
| 907 | + } else { |
|
| 908 | + $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
| 912 | + * @since 1.5.4 |
|
| 913 | + * @param string $entry_updated_message Existing message |
|
| 914 | + * @param int $view_id View ID |
|
| 915 | + * @param array $entry Gravity Forms entry array |
|
| 916 | + * @param string $back_link URL to return to the original entry. @since 1.6 |
|
| 917 | + */ |
|
| 918 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 919 | + |
|
| 920 | + echo GVCommon::generate_notice( $message ); |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + } |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * Display the Edit Entry form in the original Gravity Forms format |
|
| 928 | + * |
|
| 929 | + * @since 1.9 |
|
| 930 | + * |
|
| 931 | + * @return void |
|
| 932 | + */ |
|
| 933 | + private function render_edit_form() { |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form |
|
| 937 | + * @since 1.17 |
|
| 938 | + * @param GravityView_Edit_Entry_Render $this |
|
| 939 | + */ |
|
| 940 | + do_action( 'gravityview/edit-entry/render/before', $this ); |
|
| 941 | + |
|
| 942 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 943 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 944 | + add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 945 | + |
|
| 946 | + add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); |
|
| 947 | + add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
| 948 | + |
|
| 949 | + // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
| 950 | + unset( $_GET['page'] ); |
|
| 951 | + |
|
| 952 | + // TODO: Verify multiple-page forms |
|
| 953 | + // TODO: Product fields are not editable |
|
| 954 | + |
|
| 955 | + ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic |
|
| 956 | + |
|
| 957 | + $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 958 | + |
|
| 959 | + ob_get_clean(); |
|
| 960 | + |
|
| 961 | + remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 962 | + remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 963 | + remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 964 | + remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); |
|
| 965 | + remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
| 966 | + |
|
| 967 | + echo $html; |
|
| 968 | + |
|
| 969 | + /** |
|
| 970 | + * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form |
|
| 971 | + * @since 1.17 |
|
| 972 | + * @param GravityView_Edit_Entry_Render $this |
|
| 973 | + */ |
|
| 974 | + do_action( 'gravityview/edit-entry/render/after', $this ); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
| 979 | + * @since 1.8 |
|
| 980 | + * @return string |
|
| 981 | + */ |
|
| 982 | + public function render_form_buttons() { |
|
| 983 | + return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
| 989 | + * |
|
| 990 | + * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
| 991 | + * |
|
| 992 | + * @param array $form |
|
| 993 | + * @param boolean $ajax Whether in AJAX mode |
|
| 994 | + * @param array|string $field_values Passed parameters to the form |
|
| 995 | + * |
|
| 996 | + * @since 1.9 |
|
| 997 | + * |
|
| 998 | + * @return array Modified form array |
|
| 999 | + */ |
|
| 1000 | + public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
| 1001 | + |
|
| 1002 | + // In case we have validated the form, use it to inject the validation results into the form render |
|
| 1003 | + if( isset( $this->form_after_validation ) ) { |
|
| 1004 | + $form = $this->form_after_validation; |
|
| 1005 | + } else { |
|
| 1006 | + $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + $form = $this->filter_conditional_logic( $form ); |
|
| 1010 | + |
|
| 1011 | + $form = $this->prefill_conditional_logic( $form ); |
|
| 1012 | + |
|
| 1013 | + // for now we don't support Save and Continue feature. |
|
| 1014 | + if( ! self::$supports_save_and_continue ) { |
|
| 1015 | + unset( $form['save'] ); |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + return $form; |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * When displaying a field, check if it's a Post Field, and if so, make sure the post exists and current user has edit rights. |
|
| 1023 | + * |
|
| 1024 | + * @since 1.16.2.2 |
|
| 1025 | + * |
|
| 1026 | + * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 1027 | + * @param GF_Field $field |
|
| 1028 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 1029 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 1030 | + * @param int $form_id Form ID |
|
| 1031 | + * |
|
| 1032 | + * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next) |
|
| 1033 | + */ |
|
| 1034 | + public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 1035 | + |
|
| 1036 | + if( GFCommon::is_post_field( $field ) ) { |
|
| 1037 | + |
|
| 1038 | + $message = null; |
|
| 1039 | + |
|
| 1040 | + // First, make sure they have the capability to edit the post. |
|
| 1041 | + if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post |
|
| 1045 | + * @param string $message The existing "You don't have permission..." text |
|
| 1046 | + */ |
|
| 1047 | + $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); |
|
| 1048 | + |
|
| 1049 | + } elseif( null === get_post( $this->entry['post_id'] ) ) { |
|
| 1050 | + /** |
|
| 1051 | + * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists |
|
| 1052 | + * @param string $message The existing "This field is not editable; the post no longer exists." text |
|
| 1053 | + */ |
|
| 1054 | + $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + if( $message ) { |
|
| 1058 | + $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + return $field_content; |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * |
|
| 1067 | + * Fill-in the saved values into the form inputs |
|
| 1068 | + * |
|
| 1069 | + * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 1070 | + * @param GF_Field $field |
|
| 1071 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 1072 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 1073 | + * @param int $form_id Form ID |
|
| 1074 | + * |
|
| 1075 | + * @return mixed |
|
| 1076 | + */ |
|
| 1077 | + public function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 1078 | + |
|
| 1079 | + $gv_field = GravityView_Fields::get_associated_field( $field ); |
|
| 1080 | + |
|
| 1081 | + // If the form has been submitted, then we don't need to pre-fill the values, |
|
| 1082 | + // Except for fileupload type and when a field input is overridden- run always!! |
|
| 1083 | + if( |
|
| 1084 | + ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 1085 | + && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) |
|
| 1086 | + || ! empty( $field_content ) |
|
| 1087 | + || in_array( $field->type, array( 'honeypot' ) ) |
|
| 1088 | + || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
| 1089 | + ) { |
|
| 1090 | + return $field_content; |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + // Turn on Admin-style display for file upload fields only |
|
| 1094 | + if( 'fileupload' === $field->type ) { |
|
| 1095 | + $_GET['page'] = 'gf_entries'; |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
| 1099 | + $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
| 1100 | + |
|
| 1101 | + // add categories as choices for Post Category field |
|
| 1102 | + if ( 'post_category' === $field->type ) { |
|
| 1103 | + $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + $field_value = $this->get_field_value( $field ); |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 1110 | + * @since 1.11 |
|
| 1111 | + * @param mixed $field_value field value used to populate the input |
|
| 1112 | + * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 1113 | + */ |
|
| 1114 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
| 1115 | + |
|
| 1116 | + /** |
|
| 1117 | + * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type |
|
| 1118 | + * @since 1.17 |
|
| 1119 | + * @param mixed $field_value field value used to populate the input |
|
| 1120 | + * @param GF_Field $field Gravity Forms field object |
|
| 1121 | + */ |
|
| 1122 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field ); |
|
| 1123 | + |
|
| 1124 | + // Prevent any PHP warnings, like undefined index |
|
| 1125 | + ob_start(); |
|
| 1126 | + |
|
| 1127 | + /** @var GravityView_Field $gv_field */ |
|
| 1128 | + if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1129 | + $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
|
| 1130 | + } else { |
|
| 1131 | + $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + |
|
| 1135 | + // If there was output, it's an error |
|
| 1136 | + $warnings = ob_get_clean(); |
|
| 1137 | + |
|
| 1138 | + if( !empty( $warnings ) ) { |
|
| 1139 | + do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * Unset hack $_GET['page'] = 'gf_entries' |
|
| 1144 | + * We need the fileupload html field to render with the proper id |
|
| 1145 | + * ( <li id="field_80_16" ... > ) |
|
| 1146 | + */ |
|
| 1147 | + unset( $_GET['page'] ); |
|
| 1148 | + |
|
| 1149 | + return $return; |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * Modify the value for the current field input |
|
| 1154 | + * |
|
| 1155 | + * @param GF_Field $field |
|
| 1156 | + * |
|
| 1157 | + * @return array|mixed|string|void |
|
| 1158 | + */ |
|
| 1159 | + private function get_field_value( $field ) { |
|
| 1160 | + |
|
| 1161 | + /** |
|
| 1162 | + * @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. |
|
| 1163 | + * @param boolean True: override saved values; False: don't override (default) |
|
| 1164 | + * @param $field GF_Field object Gravity Forms field object |
|
| 1165 | + * @since 1.13 |
|
| 1166 | + */ |
|
| 1167 | + $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
| 1168 | + |
|
| 1169 | + // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
| 1170 | + if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1171 | + |
|
| 1172 | + $field_value = array(); |
|
| 1173 | + |
|
| 1174 | + // only accept pre-populated values if the field doesn't have any choice selected. |
|
| 1175 | + $allow_pre_populated = $field->allowsPrepopulate; |
|
| 1176 | + |
|
| 1177 | + foreach ( (array)$field->inputs as $input ) { |
|
| 1178 | + |
|
| 1179 | + $input_id = strval( $input['id'] ); |
|
| 1180 | 1180 | |
| 1181 | - if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
|
| 1182 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1183 | - $allow_pre_populated = false; |
|
| 1184 | - } |
|
| 1181 | + if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
|
| 1182 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1183 | + $allow_pre_populated = false; |
|
| 1184 | + } |
|
| 1185 | 1185 | |
| 1186 | - } |
|
| 1186 | + } |
|
| 1187 | 1187 | |
| 1188 | - $pre_value = $field->get_value_submission( array(), false ); |
|
| 1188 | + $pre_value = $field->get_value_submission( array(), false ); |
|
| 1189 | 1189 | |
| 1190 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1190 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1191 | 1191 | |
| 1192 | - } else { |
|
| 1192 | + } else { |
|
| 1193 | 1193 | |
| 1194 | - $id = intval( $field->id ); |
|
| 1194 | + $id = intval( $field->id ); |
|
| 1195 | 1195 | |
| 1196 | - // get pre-populated value if exists |
|
| 1197 | - $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
| 1196 | + // get pre-populated value if exists |
|
| 1197 | + $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
| 1198 | 1198 | |
| 1199 | - // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
| 1200 | - // or pre-populated value if not empty and set to override saved value |
|
| 1201 | - $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1199 | + // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
| 1200 | + // or pre-populated value if not empty and set to override saved value |
|
| 1201 | + $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1202 | 1202 | |
| 1203 | - // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
| 1204 | - if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
|
| 1205 | - $categories = array(); |
|
| 1206 | - foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
| 1207 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1208 | - } |
|
| 1209 | - $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
| 1210 | - } |
|
| 1203 | + // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
| 1204 | + if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
|
| 1205 | + $categories = array(); |
|
| 1206 | + foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
| 1207 | + $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1208 | + } |
|
| 1209 | + $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
| 1210 | + } |
|
| 1211 | 1211 | |
| 1212 | - } |
|
| 1212 | + } |
|
| 1213 | 1213 | |
| 1214 | - // if value is empty get the default value if defined |
|
| 1215 | - $field_value = $field->get_value_default_if_empty( $field_value ); |
|
| 1214 | + // if value is empty get the default value if defined |
|
| 1215 | + $field_value = $field->get_value_default_if_empty( $field_value ); |
|
| 1216 | 1216 | |
| 1217 | - return $field_value; |
|
| 1218 | - } |
|
| 1217 | + return $field_value; |
|
| 1218 | + } |
|
| 1219 | 1219 | |
| 1220 | 1220 | |
| 1221 | - // ---- Entry validation |
|
| 1221 | + // ---- Entry validation |
|
| 1222 | 1222 | |
| 1223 | - /** |
|
| 1224 | - * Add field keys that Gravity Forms expects. |
|
| 1225 | - * |
|
| 1226 | - * @see GFFormDisplay::validate() |
|
| 1227 | - * @param array $form GF Form |
|
| 1228 | - * @return array Modified GF Form |
|
| 1229 | - */ |
|
| 1230 | - public function gform_pre_validation( $form ) { |
|
| 1223 | + /** |
|
| 1224 | + * Add field keys that Gravity Forms expects. |
|
| 1225 | + * |
|
| 1226 | + * @see GFFormDisplay::validate() |
|
| 1227 | + * @param array $form GF Form |
|
| 1228 | + * @return array Modified GF Form |
|
| 1229 | + */ |
|
| 1230 | + public function gform_pre_validation( $form ) { |
|
| 1231 | 1231 | |
| 1232 | - if( ! $this->verify_nonce() ) { |
|
| 1233 | - return $form; |
|
| 1234 | - } |
|
| 1232 | + if( ! $this->verify_nonce() ) { |
|
| 1233 | + return $form; |
|
| 1234 | + } |
|
| 1235 | 1235 | |
| 1236 | - // Fix PHP warning regarding undefined index. |
|
| 1237 | - foreach ( $form['fields'] as &$field) { |
|
| 1236 | + // Fix PHP warning regarding undefined index. |
|
| 1237 | + foreach ( $form['fields'] as &$field) { |
|
| 1238 | 1238 | |
| 1239 | - // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
| 1240 | - // expects certain field array items to be set. |
|
| 1241 | - foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
| 1242 | - $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 1243 | - } |
|
| 1239 | + // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
| 1240 | + // expects certain field array items to be set. |
|
| 1241 | + foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
| 1242 | + $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 1243 | + } |
|
| 1244 | 1244 | |
| 1245 | - // unset emailConfirmEnabled for email type fields |
|
| 1246 | - /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
| 1245 | + // unset emailConfirmEnabled for email type fields |
|
| 1246 | + /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
| 1247 | 1247 | $field['emailConfirmEnabled'] = ''; |
| 1248 | 1248 | }*/ |
| 1249 | 1249 | |
| 1250 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 1250 | + switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 1251 | + |
|
| 1252 | + /** |
|
| 1253 | + * 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. |
|
| 1254 | + * |
|
| 1255 | + * 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. |
|
| 1256 | + * |
|
| 1257 | + * @hack |
|
| 1258 | + */ |
|
| 1259 | + case 'fileupload': |
|
| 1260 | + |
|
| 1261 | + // Set the previous value |
|
| 1262 | + $entry = $this->get_entry(); |
|
| 1251 | 1263 | |
| 1252 | - /** |
|
| 1253 | - * 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. |
|
| 1254 | - * |
|
| 1255 | - * 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. |
|
| 1256 | - * |
|
| 1257 | - * @hack |
|
| 1258 | - */ |
|
| 1259 | - case 'fileupload': |
|
| 1260 | - |
|
| 1261 | - // Set the previous value |
|
| 1262 | - $entry = $this->get_entry(); |
|
| 1263 | - |
|
| 1264 | - $input_name = 'input_'.$field->id; |
|
| 1265 | - $form_id = $form['id']; |
|
| 1266 | - |
|
| 1267 | - $value = NULL; |
|
| 1268 | - |
|
| 1269 | - // Use the previous entry value as the default. |
|
| 1270 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1271 | - $value = $entry[ $field->id ]; |
|
| 1272 | - } |
|
| 1264 | + $input_name = 'input_'.$field->id; |
|
| 1265 | + $form_id = $form['id']; |
|
| 1273 | 1266 | |
| 1274 | - // If this is a single upload file |
|
| 1275 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1276 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1277 | - $value = $file_path['url']; |
|
| 1267 | + $value = NULL; |
|
| 1278 | 1268 | |
| 1279 | - } else { |
|
| 1280 | - |
|
| 1281 | - // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 1282 | - // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 1283 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1284 | - |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - if( rgar($field, "multipleFiles") ) { |
|
| 1288 | - |
|
| 1289 | - // If there are fresh uploads, process and merge them. |
|
| 1290 | - // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 1291 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1292 | - $value = empty( $value ) ? '[]' : $value; |
|
| 1293 | - $value = stripslashes_deep( $value ); |
|
| 1294 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1295 | - } |
|
| 1269 | + // Use the previous entry value as the default. |
|
| 1270 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1271 | + $value = $entry[ $field->id ]; |
|
| 1272 | + } |
|
| 1296 | 1273 | |
| 1297 | - } else { |
|
| 1274 | + // If this is a single upload file |
|
| 1275 | + if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1276 | + $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1277 | + $value = $file_path['url']; |
|
| 1298 | 1278 | |
| 1299 | - // A file already exists when editing an entry |
|
| 1300 | - // We set this to solve issue when file upload fields are required. |
|
| 1301 | - GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 1279 | + } else { |
|
| 1302 | 1280 | |
| 1303 | - } |
|
| 1281 | + // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 1282 | + // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 1283 | + $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1304 | 1284 | |
| 1305 | - $this->entry[ $input_name ] = $value; |
|
| 1306 | - $_POST[ $input_name ] = $value; |
|
| 1285 | + } |
|
| 1307 | 1286 | |
| 1308 | - break; |
|
| 1287 | + if( rgar($field, "multipleFiles") ) { |
|
| 1309 | 1288 | |
| 1310 | - case 'number': |
|
| 1311 | - // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 1312 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1313 | - $_POST['input_'.$field->id ] = NULL; |
|
| 1314 | - } |
|
| 1315 | - break; |
|
| 1316 | - case 'captcha': |
|
| 1317 | - // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
| 1318 | - $_POST['recaptcha_challenge_field'] = NULL; |
|
| 1319 | - $_POST['recaptcha_response_field'] = NULL; |
|
| 1320 | - break; |
|
| 1321 | - } |
|
| 1289 | + // If there are fresh uploads, process and merge them. |
|
| 1290 | + // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 1291 | + if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1292 | + $value = empty( $value ) ? '[]' : $value; |
|
| 1293 | + $value = stripslashes_deep( $value ); |
|
| 1294 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1295 | + } |
|
| 1322 | 1296 | |
| 1323 | - } |
|
| 1297 | + } else { |
|
| 1324 | 1298 | |
| 1325 | - return $form; |
|
| 1326 | - } |
|
| 1299 | + // A file already exists when editing an entry |
|
| 1300 | + // We set this to solve issue when file upload fields are required. |
|
| 1301 | + GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 1327 | 1302 | |
| 1303 | + } |
|
| 1328 | 1304 | |
| 1329 | - /** |
|
| 1330 | - * Process validation for a edit entry submission |
|
| 1331 | - * |
|
| 1332 | - * Sets the `is_valid` object var |
|
| 1333 | - * |
|
| 1334 | - * @return void |
|
| 1335 | - */ |
|
| 1336 | - private function validate() { |
|
| 1305 | + $this->entry[ $input_name ] = $value; |
|
| 1306 | + $_POST[ $input_name ] = $value; |
|
| 1337 | 1307 | |
| 1338 | - /** |
|
| 1339 | - * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
| 1340 | - * GF User Registration Add-on version > 3.x has a different class name |
|
| 1341 | - * @since 1.16.2 |
|
| 1342 | - */ |
|
| 1343 | - if ( class_exists( 'GF_User_Registration' ) ) { |
|
| 1344 | - remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) ); |
|
| 1345 | - } else if ( class_exists( 'GFUser' ) ) { |
|
| 1346 | - remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
| 1347 | - } |
|
| 1308 | + break; |
|
| 1348 | 1309 | |
| 1310 | + case 'number': |
|
| 1311 | + // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 1312 | + if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1313 | + $_POST['input_'.$field->id ] = NULL; |
|
| 1314 | + } |
|
| 1315 | + break; |
|
| 1316 | + case 'captcha': |
|
| 1317 | + // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
| 1318 | + $_POST['recaptcha_challenge_field'] = NULL; |
|
| 1319 | + $_POST['recaptcha_response_field'] = NULL; |
|
| 1320 | + break; |
|
| 1321 | + } |
|
| 1349 | 1322 | |
| 1350 | - /** |
|
| 1351 | - * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
| 1352 | - * You can enter whatever you want! |
|
| 1353 | - * We try validating, and customize the results using `self::custom_validation()` |
|
| 1354 | - */ |
|
| 1355 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + return $form; |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + |
|
| 1329 | + /** |
|
| 1330 | + * Process validation for a edit entry submission |
|
| 1331 | + * |
|
| 1332 | + * Sets the `is_valid` object var |
|
| 1333 | + * |
|
| 1334 | + * @return void |
|
| 1335 | + */ |
|
| 1336 | + private function validate() { |
|
| 1337 | + |
|
| 1338 | + /** |
|
| 1339 | + * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
| 1340 | + * GF User Registration Add-on version > 3.x has a different class name |
|
| 1341 | + * @since 1.16.2 |
|
| 1342 | + */ |
|
| 1343 | + if ( class_exists( 'GF_User_Registration' ) ) { |
|
| 1344 | + remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) ); |
|
| 1345 | + } else if ( class_exists( 'GFUser' ) ) { |
|
| 1346 | + remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
| 1347 | + } |
|
| 1356 | 1348 | |
| 1357 | - // Needed by the validate funtion |
|
| 1358 | - $failed_validation_page = NULL; |
|
| 1359 | - $field_values = RGForms::post( 'gform_field_values' ); |
|
| 1360 | 1349 | |
| 1361 | - // Prevent entry limit from running when editing an entry, also |
|
| 1362 | - // prevent form scheduling from preventing editing |
|
| 1363 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 1350 | + /** |
|
| 1351 | + * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
| 1352 | + * You can enter whatever you want! |
|
| 1353 | + * We try validating, and customize the results using `self::custom_validation()` |
|
| 1354 | + */ |
|
| 1355 | + add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 1364 | 1356 | |
| 1365 | - // Hide fields depending on Edit Entry settings |
|
| 1366 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1357 | + // Needed by the validate funtion |
|
| 1358 | + $failed_validation_page = NULL; |
|
| 1359 | + $field_values = RGForms::post( 'gform_field_values' ); |
|
| 1367 | 1360 | |
| 1368 | - $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
| 1361 | + // Prevent entry limit from running when editing an entry, also |
|
| 1362 | + // prevent form scheduling from preventing editing |
|
| 1363 | + unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 1369 | 1364 | |
| 1370 | - remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1371 | - } |
|
| 1365 | + // Hide fields depending on Edit Entry settings |
|
| 1366 | + $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1367 | + |
|
| 1368 | + $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
| 1369 | + |
|
| 1370 | + remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1371 | + } |
|
| 1372 | 1372 | |
| 1373 | 1373 | |
| 1374 | - /** |
|
| 1375 | - * Make validation work for Edit Entry |
|
| 1376 | - * |
|
| 1377 | - * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
| 1378 | - * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
| 1379 | - * fields. This goes through all the fields and if they're an invalid post field, we |
|
| 1380 | - * set them as valid. If there are still issues, we'll return false. |
|
| 1381 | - * |
|
| 1382 | - * @param [type] $validation_results [description] |
|
| 1383 | - * @return [type] [description] |
|
| 1384 | - */ |
|
| 1385 | - public function custom_validation( $validation_results ) { |
|
| 1374 | + /** |
|
| 1375 | + * Make validation work for Edit Entry |
|
| 1376 | + * |
|
| 1377 | + * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
| 1378 | + * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
| 1379 | + * fields. This goes through all the fields and if they're an invalid post field, we |
|
| 1380 | + * set them as valid. If there are still issues, we'll return false. |
|
| 1381 | + * |
|
| 1382 | + * @param [type] $validation_results [description] |
|
| 1383 | + * @return [type] [description] |
|
| 1384 | + */ |
|
| 1385 | + public function custom_validation( $validation_results ) { |
|
| 1386 | 1386 | |
| 1387 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1387 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1388 | 1388 | |
| 1389 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1389 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1390 | 1390 | |
| 1391 | - $gv_valid = true; |
|
| 1391 | + $gv_valid = true; |
|
| 1392 | 1392 | |
| 1393 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1393 | + foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1394 | 1394 | |
| 1395 | - $value = RGFormsModel::get_field_value( $field ); |
|
| 1396 | - $field_type = RGFormsModel::get_input_type( $field ); |
|
| 1395 | + $value = RGFormsModel::get_field_value( $field ); |
|
| 1396 | + $field_type = RGFormsModel::get_input_type( $field ); |
|
| 1397 | 1397 | |
| 1398 | - // Validate always |
|
| 1399 | - switch ( $field_type ) { |
|
| 1398 | + // Validate always |
|
| 1399 | + switch ( $field_type ) { |
|
| 1400 | 1400 | |
| 1401 | 1401 | |
| 1402 | - case 'fileupload' : |
|
| 1403 | - case 'post_image': |
|
| 1402 | + case 'fileupload' : |
|
| 1403 | + case 'post_image': |
|
| 1404 | 1404 | |
| 1405 | - // in case nothing is uploaded but there are already files saved |
|
| 1406 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1407 | - $field->failed_validation = false; |
|
| 1408 | - unset( $field->validation_message ); |
|
| 1409 | - } |
|
| 1405 | + // in case nothing is uploaded but there are already files saved |
|
| 1406 | + if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1407 | + $field->failed_validation = false; |
|
| 1408 | + unset( $field->validation_message ); |
|
| 1409 | + } |
|
| 1410 | 1410 | |
| 1411 | - // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1412 | - if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1411 | + // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1412 | + if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1413 | 1413 | |
| 1414 | - $input_name = 'input_' . $field->id; |
|
| 1415 | - //uploaded |
|
| 1416 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1414 | + $input_name = 'input_' . $field->id; |
|
| 1415 | + //uploaded |
|
| 1416 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1417 | 1417 | |
| 1418 | - //existent |
|
| 1419 | - $entry = $this->get_entry(); |
|
| 1420 | - $value = NULL; |
|
| 1421 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1422 | - $value = json_decode( $entry[ $field->id ], true ); |
|
| 1423 | - } |
|
| 1418 | + //existent |
|
| 1419 | + $entry = $this->get_entry(); |
|
| 1420 | + $value = NULL; |
|
| 1421 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1422 | + $value = json_decode( $entry[ $field->id ], true ); |
|
| 1423 | + } |
|
| 1424 | 1424 | |
| 1425 | - // count uploaded files and existent entry files |
|
| 1426 | - $count_files = count( $file_names ) + count( $value ); |
|
| 1425 | + // count uploaded files and existent entry files |
|
| 1426 | + $count_files = count( $file_names ) + count( $value ); |
|
| 1427 | 1427 | |
| 1428 | - if( $count_files > $field->maxFiles ) { |
|
| 1429 | - $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1430 | - $field->failed_validation = 1; |
|
| 1431 | - $gv_valid = false; |
|
| 1428 | + if( $count_files > $field->maxFiles ) { |
|
| 1429 | + $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1430 | + $field->failed_validation = 1; |
|
| 1431 | + $gv_valid = false; |
|
| 1432 | 1432 | |
| 1433 | - // in case of error make sure the newest upload files are removed from the upload input |
|
| 1434 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1435 | - } |
|
| 1433 | + // in case of error make sure the newest upload files are removed from the upload input |
|
| 1434 | + GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1435 | + } |
|
| 1436 | 1436 | |
| 1437 | - } |
|
| 1437 | + } |
|
| 1438 | 1438 | |
| 1439 | 1439 | |
| 1440 | - break; |
|
| 1440 | + break; |
|
| 1441 | 1441 | |
| 1442 | - } |
|
| 1442 | + } |
|
| 1443 | 1443 | |
| 1444 | - // This field has failed validation. |
|
| 1445 | - if( !empty( $field->failed_validation ) ) { |
|
| 1444 | + // This field has failed validation. |
|
| 1445 | + if( !empty( $field->failed_validation ) ) { |
|
| 1446 | 1446 | |
| 1447 | - do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
| 1447 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
| 1448 | 1448 | |
| 1449 | - switch ( $field_type ) { |
|
| 1449 | + switch ( $field_type ) { |
|
| 1450 | 1450 | |
| 1451 | - // Captchas don't need to be re-entered. |
|
| 1452 | - case 'captcha': |
|
| 1451 | + // Captchas don't need to be re-entered. |
|
| 1452 | + case 'captcha': |
|
| 1453 | 1453 | |
| 1454 | - // Post Image fields aren't editable, so we un-fail them. |
|
| 1455 | - case 'post_image': |
|
| 1456 | - $field->failed_validation = false; |
|
| 1457 | - unset( $field->validation_message ); |
|
| 1458 | - break; |
|
| 1454 | + // Post Image fields aren't editable, so we un-fail them. |
|
| 1455 | + case 'post_image': |
|
| 1456 | + $field->failed_validation = false; |
|
| 1457 | + unset( $field->validation_message ); |
|
| 1458 | + break; |
|
| 1459 | 1459 | |
| 1460 | - } |
|
| 1460 | + } |
|
| 1461 | 1461 | |
| 1462 | - // You can't continue inside a switch, so we do it after. |
|
| 1463 | - if( empty( $field->failed_validation ) ) { |
|
| 1464 | - continue; |
|
| 1465 | - } |
|
| 1462 | + // You can't continue inside a switch, so we do it after. |
|
| 1463 | + if( empty( $field->failed_validation ) ) { |
|
| 1464 | + continue; |
|
| 1465 | + } |
|
| 1466 | 1466 | |
| 1467 | - // checks if the No Duplicates option is not validating entry against itself, since |
|
| 1468 | - // we're editing a stored entry, it would also assume it's a duplicate. |
|
| 1469 | - if( !empty( $field->noDuplicates ) ) { |
|
| 1467 | + // checks if the No Duplicates option is not validating entry against itself, since |
|
| 1468 | + // we're editing a stored entry, it would also assume it's a duplicate. |
|
| 1469 | + if( !empty( $field->noDuplicates ) ) { |
|
| 1470 | 1470 | |
| 1471 | - $entry = $this->get_entry(); |
|
| 1471 | + $entry = $this->get_entry(); |
|
| 1472 | 1472 | |
| 1473 | - // If the value of the entry is the same as the stored value |
|
| 1474 | - // Then we can assume it's not a duplicate, it's the same. |
|
| 1475 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1476 | - //if value submitted was not changed, then don't validate |
|
| 1477 | - $field->failed_validation = false; |
|
| 1473 | + // If the value of the entry is the same as the stored value |
|
| 1474 | + // Then we can assume it's not a duplicate, it's the same. |
|
| 1475 | + if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1476 | + //if value submitted was not changed, then don't validate |
|
| 1477 | + $field->failed_validation = false; |
|
| 1478 | 1478 | |
| 1479 | - unset( $field->validation_message ); |
|
| 1479 | + unset( $field->validation_message ); |
|
| 1480 | 1480 | |
| 1481 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1481 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1482 | 1482 | |
| 1483 | - continue; |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1483 | + continue; |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | 1486 | |
| 1487 | - // if here then probably we are facing the validation 'At least one field must be filled out' |
|
| 1488 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1489 | - unset( $field->validation_message ); |
|
| 1490 | - $field->validation_message = false; |
|
| 1491 | - continue; |
|
| 1492 | - } |
|
| 1487 | + // if here then probably we are facing the validation 'At least one field must be filled out' |
|
| 1488 | + if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1489 | + unset( $field->validation_message ); |
|
| 1490 | + $field->validation_message = false; |
|
| 1491 | + continue; |
|
| 1492 | + } |
|
| 1493 | 1493 | |
| 1494 | - $gv_valid = false; |
|
| 1494 | + $gv_valid = false; |
|
| 1495 | 1495 | |
| 1496 | - } |
|
| 1496 | + } |
|
| 1497 | 1497 | |
| 1498 | - } |
|
| 1498 | + } |
|
| 1499 | 1499 | |
| 1500 | - $validation_results['is_valid'] = $gv_valid; |
|
| 1500 | + $validation_results['is_valid'] = $gv_valid; |
|
| 1501 | 1501 | |
| 1502 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1502 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1503 | 1503 | |
| 1504 | - // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
| 1505 | - $this->form_after_validation = $validation_results['form']; |
|
| 1504 | + // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
| 1505 | + $this->form_after_validation = $validation_results['form']; |
|
| 1506 | 1506 | |
| 1507 | - return $validation_results; |
|
| 1508 | - } |
|
| 1507 | + return $validation_results; |
|
| 1508 | + } |
|
| 1509 | 1509 | |
| 1510 | 1510 | |
| 1511 | - /** |
|
| 1512 | - * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
| 1513 | - * Get the current entry and set it if it's not yet set. |
|
| 1514 | - * @return array Gravity Forms entry array |
|
| 1515 | - */ |
|
| 1516 | - public function get_entry() { |
|
| 1511 | + /** |
|
| 1512 | + * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
| 1513 | + * Get the current entry and set it if it's not yet set. |
|
| 1514 | + * @return array Gravity Forms entry array |
|
| 1515 | + */ |
|
| 1516 | + public function get_entry() { |
|
| 1517 | 1517 | |
| 1518 | - if( empty( $this->entry ) ) { |
|
| 1519 | - // Get the database value of the entry that's being edited |
|
| 1520 | - $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
| 1521 | - } |
|
| 1518 | + if( empty( $this->entry ) ) { |
|
| 1519 | + // Get the database value of the entry that's being edited |
|
| 1520 | + $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
| 1521 | + } |
|
| 1522 | 1522 | |
| 1523 | - return $this->entry; |
|
| 1524 | - } |
|
| 1523 | + return $this->entry; |
|
| 1524 | + } |
|
| 1525 | 1525 | |
| 1526 | 1526 | |
| 1527 | 1527 | |
| 1528 | - // --- Filters |
|
| 1528 | + // --- Filters |
|
| 1529 | 1529 | |
| 1530 | - /** |
|
| 1531 | - * Get the Edit Entry fields as configured in the View |
|
| 1532 | - * |
|
| 1533 | - * @since 1.8 |
|
| 1534 | - * |
|
| 1535 | - * @param int $view_id |
|
| 1536 | - * |
|
| 1537 | - * @return array Array of fields that are configured in the Edit tab in the Admin |
|
| 1538 | - */ |
|
| 1539 | - private function get_configured_edit_fields( $form, $view_id ) { |
|
| 1530 | + /** |
|
| 1531 | + * Get the Edit Entry fields as configured in the View |
|
| 1532 | + * |
|
| 1533 | + * @since 1.8 |
|
| 1534 | + * |
|
| 1535 | + * @param int $view_id |
|
| 1536 | + * |
|
| 1537 | + * @return array Array of fields that are configured in the Edit tab in the Admin |
|
| 1538 | + */ |
|
| 1539 | + private function get_configured_edit_fields( $form, $view_id ) { |
|
| 1540 | 1540 | |
| 1541 | - // Get all fields for form |
|
| 1542 | - $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
| 1541 | + // Get all fields for form |
|
| 1542 | + $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
| 1543 | 1543 | |
| 1544 | - // If edit tab not yet configured, show all fields |
|
| 1545 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1544 | + // If edit tab not yet configured, show all fields |
|
| 1545 | + $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1546 | 1546 | |
| 1547 | - // Show hidden fields as text fields |
|
| 1548 | - $form = $this->fix_survey_fields( $form ); |
|
| 1547 | + // Show hidden fields as text fields |
|
| 1548 | + $form = $this->fix_survey_fields( $form ); |
|
| 1549 | 1549 | |
| 1550 | - // Hide fields depending on admin settings |
|
| 1551 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1550 | + // Hide fields depending on admin settings |
|
| 1551 | + $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1552 | 1552 | |
| 1553 | - // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1554 | - $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1553 | + // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1554 | + $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1555 | 1555 | |
| 1556 | - /** |
|
| 1557 | - * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form |
|
| 1558 | - * @since 1.17 |
|
| 1559 | - * @param GF_Field[] $fields Gravity Forms form fields |
|
| 1560 | - * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1561 | - * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry) |
|
| 1562 | - * @param int $view_id View ID |
|
| 1563 | - */ |
|
| 1564 | - $fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id ); |
|
| 1556 | + /** |
|
| 1557 | + * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form |
|
| 1558 | + * @since 1.17 |
|
| 1559 | + * @param GF_Field[] $fields Gravity Forms form fields |
|
| 1560 | + * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1561 | + * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry) |
|
| 1562 | + * @param int $view_id View ID |
|
| 1563 | + */ |
|
| 1564 | + $fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id ); |
|
| 1565 | 1565 | |
| 1566 | - return $fields; |
|
| 1567 | - } |
|
| 1566 | + return $fields; |
|
| 1567 | + } |
|
| 1568 | 1568 | |
| 1569 | - /** |
|
| 1570 | - * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in |
|
| 1571 | - * |
|
| 1572 | - * @since 1.16.4 |
|
| 1573 | - * |
|
| 1574 | - * @param array $form |
|
| 1575 | - * |
|
| 1576 | - * @return array Form, with all fields set to `allowsPrepopulate => true` |
|
| 1577 | - */ |
|
| 1578 | - private function fix_survey_fields( $form ) { |
|
| 1569 | + /** |
|
| 1570 | + * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in |
|
| 1571 | + * |
|
| 1572 | + * @since 1.16.4 |
|
| 1573 | + * |
|
| 1574 | + * @param array $form |
|
| 1575 | + * |
|
| 1576 | + * @return array Form, with all fields set to `allowsPrepopulate => true` |
|
| 1577 | + */ |
|
| 1578 | + private function fix_survey_fields( $form ) { |
|
| 1579 | 1579 | |
| 1580 | - /** @var GF_Field $field */ |
|
| 1581 | - foreach( $form['fields'] as &$field ) { |
|
| 1582 | - $field->allowsPrepopulate = true; |
|
| 1583 | - } |
|
| 1580 | + /** @var GF_Field $field */ |
|
| 1581 | + foreach( $form['fields'] as &$field ) { |
|
| 1582 | + $field->allowsPrepopulate = true; |
|
| 1583 | + } |
|
| 1584 | 1584 | |
| 1585 | - return $form; |
|
| 1586 | - } |
|
| 1585 | + return $form; |
|
| 1586 | + } |
|
| 1587 | 1587 | |
| 1588 | 1588 | |
| 1589 | - /** |
|
| 1590 | - * Filter area fields based on specified conditions |
|
| 1591 | - * - This filter removes the fields that have calculation configured |
|
| 1592 | - * |
|
| 1593 | - * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
| 1594 | - * @access private |
|
| 1595 | - * @param GF_Field[] $fields |
|
| 1596 | - * @param array $configured_fields |
|
| 1597 | - * @since 1.5 |
|
| 1598 | - * @return array $fields |
|
| 1599 | - */ |
|
| 1600 | - private function filter_fields( $fields, $configured_fields ) { |
|
| 1601 | - |
|
| 1602 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1603 | - return $fields; |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - $edit_fields = array(); |
|
| 1607 | - |
|
| 1608 | - $field_type_blacklist = array( |
|
| 1609 | - 'page', |
|
| 1610 | - ); |
|
| 1611 | - |
|
| 1612 | - /** |
|
| 1613 | - * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
| 1614 | - * @since 1.9.1 |
|
| 1615 | - * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
| 1616 | - */ |
|
| 1617 | - $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
| 1618 | - |
|
| 1619 | - if( $hide_product_fields ) { |
|
| 1620 | - $field_type_blacklist[] = 'option'; |
|
| 1621 | - $field_type_blacklist[] = 'quantity'; |
|
| 1622 | - $field_type_blacklist[] = 'product'; |
|
| 1623 | - $field_type_blacklist[] = 'total'; |
|
| 1624 | - $field_type_blacklist[] = 'shipping'; |
|
| 1625 | - $field_type_blacklist[] = 'calculation'; |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - // First, remove blacklist or calculation fields |
|
| 1629 | - foreach ( $fields as $key => $field ) { |
|
| 1630 | - |
|
| 1631 | - // Remove the fields that have calculation properties and keep them to be used later |
|
| 1632 | - // @since 1.16.2 |
|
| 1633 | - if( $field->has_calculation() ) { |
|
| 1634 | - $this->fields_with_calculation[] = $field; |
|
| 1635 | - // don't remove the calculation fields on form render. |
|
| 1636 | - } |
|
| 1637 | - |
|
| 1638 | - // process total field after all fields have been saved |
|
| 1639 | - if ( $field->type == 'total' ) { |
|
| 1640 | - $this->total_fields[] = $field; |
|
| 1641 | - unset( $fields[ $key ] ); |
|
| 1642 | - } |
|
| 1643 | - |
|
| 1644 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1645 | - unset( $fields[ $key ] ); |
|
| 1646 | - } |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - // The Edit tab has not been configured, so we return all fields by default. |
|
| 1650 | - if( empty( $configured_fields ) ) { |
|
| 1651 | - return $fields; |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - // The edit tab has been configured, so we loop through to configured settings |
|
| 1655 | - foreach ( $configured_fields as $configured_field ) { |
|
| 1656 | - |
|
| 1657 | - /** @var GF_Field $field */ |
|
| 1658 | - foreach ( $fields as $field ) { |
|
| 1659 | - |
|
| 1660 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1661 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1662 | - break; |
|
| 1663 | - } |
|
| 1664 | - |
|
| 1665 | - } |
|
| 1666 | - |
|
| 1667 | - } |
|
| 1668 | - |
|
| 1669 | - return $edit_fields; |
|
| 1670 | - |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - /** |
|
| 1674 | - * Override GF Form field properties with the ones defined on the View |
|
| 1675 | - * @param GF_Field $field GF Form field object |
|
| 1676 | - * @param array $field_setting GV field options |
|
| 1677 | - * @since 1.5 |
|
| 1678 | - * @return array|GF_Field |
|
| 1679 | - */ |
|
| 1680 | - private function merge_field_properties( $field, $field_setting ) { |
|
| 1681 | - |
|
| 1682 | - $return_field = $field; |
|
| 1683 | - |
|
| 1684 | - if( empty( $field_setting['show_label'] ) ) { |
|
| 1685 | - $return_field->label = ''; |
|
| 1686 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1687 | - $return_field->label = $field_setting['custom_label']; |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1691 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - /** |
|
| 1695 | - * Normalize page numbers - avoid conflicts with page validation |
|
| 1696 | - * @since 1.6 |
|
| 1697 | - */ |
|
| 1698 | - $return_field->pageNumber = 1; |
|
| 1699 | - |
|
| 1700 | - return $return_field; |
|
| 1701 | - |
|
| 1702 | - } |
|
| 1703 | - |
|
| 1704 | - /** |
|
| 1705 | - * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
| 1706 | - * |
|
| 1707 | - * @since 1.9.1 |
|
| 1708 | - * |
|
| 1709 | - * @param array|GF_Field[] $fields Gravity Forms form fields |
|
| 1710 | - * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1711 | - * @param array $form GF Form array |
|
| 1712 | - * @param int $view_id View ID |
|
| 1713 | - * |
|
| 1714 | - * @return array Possibly modified form array |
|
| 1715 | - */ |
|
| 1716 | - private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
| 1717 | - |
|
| 1718 | - /** |
|
| 1719 | - * @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 |
|
| 1720 | - * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1721 | - * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1722 | - * @since 1.9.1 |
|
| 1723 | - * @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. |
|
| 1724 | - * @param array $form GF Form array |
|
| 1725 | - * @param int $view_id View ID |
|
| 1726 | - */ |
|
| 1727 | - $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1728 | - |
|
| 1729 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1730 | - foreach( $fields as $k => $field ) { |
|
| 1731 | - if( $field->adminOnly ) { |
|
| 1732 | - unset( $fields[ $k ] ); |
|
| 1733 | - } |
|
| 1734 | - } |
|
| 1735 | - return $fields; |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - foreach( $fields as &$field ) { |
|
| 1739 | - $field->adminOnly = false; |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - return $fields; |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - // --- Conditional Logic |
|
| 1746 | - |
|
| 1747 | - /** |
|
| 1748 | - * Conditional logic isn't designed to work with forms that already have content. When switching input values, |
|
| 1749 | - * the dependent fields will be blank. |
|
| 1750 | - * |
|
| 1751 | - * Note: This is because GF populates a JavaScript variable with the input values. This is tough to filter at the input level; |
|
| 1752 | - * via the `gform_field_value` filter; it requires lots of legwork. Doing it at the form level is easier. |
|
| 1753 | - * |
|
| 1754 | - * @since 1.17.4 |
|
| 1755 | - * |
|
| 1756 | - * @param array $form Gravity Forms array object |
|
| 1757 | - * |
|
| 1758 | - * @return array $form, modified to fix conditional |
|
| 1759 | - */ |
|
| 1760 | - function prefill_conditional_logic( $form ) { |
|
| 1761 | - |
|
| 1762 | - if( ! GFFormDisplay::has_conditional_logic( $form ) ) { |
|
| 1763 | - return $form; |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - // Have Conditional Logic pre-fill fields as if the data were default values |
|
| 1767 | - /** @var GF_Field $field */ |
|
| 1768 | - foreach ( $form['fields'] as &$field ) { |
|
| 1769 | - |
|
| 1770 | - if( 'checkbox' === $field->type ) { |
|
| 1771 | - foreach ( $field->get_entry_inputs() as $key => $input ) { |
|
| 1772 | - $input_id = $input['id']; |
|
| 1773 | - $choice = $field->choices[ $key ]; |
|
| 1774 | - $value = rgar( $this->entry, $input_id ); |
|
| 1775 | - $match = RGFormsModel::choice_value_match( $field, $choice, $value ); |
|
| 1776 | - if( $match ) { |
|
| 1777 | - $field->choices[ $key ]['isSelected'] = true; |
|
| 1778 | - } |
|
| 1779 | - } |
|
| 1780 | - } else { |
|
| 1781 | - |
|
| 1782 | - // We need to run through each field to set the default values |
|
| 1783 | - foreach ( $this->entry as $field_id => $field_value ) { |
|
| 1784 | - |
|
| 1785 | - if( floatval( $field_id ) === floatval( $field->id ) ) { |
|
| 1786 | - |
|
| 1787 | - if( 'list' === $field->type ) { |
|
| 1788 | - $list_rows = maybe_unserialize( $field_value ); |
|
| 1789 | - |
|
| 1790 | - $list_field_value = array(); |
|
| 1791 | - foreach ( $list_rows as $row ) { |
|
| 1792 | - foreach ( $row as $column ) { |
|
| 1793 | - $list_field_value[] = $column; |
|
| 1794 | - } |
|
| 1795 | - } |
|
| 1796 | - |
|
| 1797 | - $field->defaultValue = $list_field_value; |
|
| 1798 | - } else { |
|
| 1799 | - $field->defaultValue = $field_value; |
|
| 1800 | - } |
|
| 1801 | - } |
|
| 1802 | - } |
|
| 1803 | - } |
|
| 1804 | - } |
|
| 1805 | - |
|
| 1806 | - return $form; |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - /** |
|
| 1810 | - * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
| 1811 | - * |
|
| 1812 | - * @todo Merge with caller method |
|
| 1813 | - * @since 1.9 |
|
| 1814 | - * |
|
| 1815 | - * @param array $form Gravity Forms form |
|
| 1816 | - * @return array Modified form, if not using Conditional Logic |
|
| 1817 | - */ |
|
| 1818 | - private function filter_conditional_logic( $form ) { |
|
| 1819 | - |
|
| 1820 | - /** |
|
| 1821 | - * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
| 1822 | - * @since 1.9 |
|
| 1823 | - * @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 |
|
| 1824 | - * @param array $form Gravity Forms form |
|
| 1825 | - */ |
|
| 1826 | - $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
| 1827 | - |
|
| 1828 | - if( $use_conditional_logic ) { |
|
| 1829 | - return $form; |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - foreach( $form['fields'] as &$field ) { |
|
| 1833 | - /* @var GF_Field $field */ |
|
| 1834 | - $field->conditionalLogic = null; |
|
| 1835 | - } |
|
| 1836 | - |
|
| 1837 | - unset( $form['button']['conditionalLogic'] ); |
|
| 1838 | - |
|
| 1839 | - return $form; |
|
| 1840 | - |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - /** |
|
| 1844 | - * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
| 1845 | - * |
|
| 1846 | - * @since 1.9 |
|
| 1847 | - * |
|
| 1848 | - * @param $has_conditional_logic |
|
| 1849 | - * @param $form |
|
| 1850 | - * @return mixed|void |
|
| 1851 | - */ |
|
| 1852 | - public function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
| 1853 | - |
|
| 1854 | - if( ! $this->is_edit_entry() ) { |
|
| 1855 | - return $has_conditional_logic; |
|
| 1856 | - } |
|
| 1857 | - |
|
| 1858 | - /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */ |
|
| 1859 | - return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - // --- User checks and nonces |
|
| 1864 | - |
|
| 1865 | - /** |
|
| 1866 | - * Check if the user can edit the entry |
|
| 1867 | - * |
|
| 1868 | - * - Is the nonce valid? |
|
| 1869 | - * - Does the user have the right caps for the entry |
|
| 1870 | - * - Is the entry in the trash? |
|
| 1871 | - * |
|
| 1872 | - * @todo Move to GVCommon |
|
| 1873 | - * |
|
| 1874 | - * @param boolean $echo Show error messages in the form? |
|
| 1875 | - * @return boolean True: can edit form. False: nope. |
|
| 1876 | - */ |
|
| 1877 | - private function user_can_edit_entry( $echo = false ) { |
|
| 1878 | - |
|
| 1879 | - $error = NULL; |
|
| 1880 | - |
|
| 1881 | - /** |
|
| 1882 | - * 1. Permalinks are turned off |
|
| 1883 | - * 2. There are two entries embedded using oEmbed |
|
| 1884 | - * 3. One of the entries has just been saved |
|
| 1885 | - */ |
|
| 1886 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1887 | - |
|
| 1888 | - $error = true; |
|
| 1889 | - |
|
| 1890 | - } |
|
| 1891 | - |
|
| 1892 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1893 | - |
|
| 1894 | - $error = true; |
|
| 1895 | - |
|
| 1896 | - } elseif( ! $this->verify_nonce() ) { |
|
| 1897 | - |
|
| 1898 | - /** |
|
| 1899 | - * If the Entry is embedded, there may be two entries on the same page. |
|
| 1900 | - * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
| 1901 | - */ |
|
| 1902 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1903 | - $error = true; |
|
| 1904 | - } else { |
|
| 1905 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1906 | - } |
|
| 1907 | - |
|
| 1908 | - } |
|
| 1909 | - |
|
| 1910 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1911 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1912 | - } |
|
| 1913 | - |
|
| 1914 | - if( $this->entry['status'] === 'trash' ) { |
|
| 1915 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1916 | - } |
|
| 1589 | + /** |
|
| 1590 | + * Filter area fields based on specified conditions |
|
| 1591 | + * - This filter removes the fields that have calculation configured |
|
| 1592 | + * |
|
| 1593 | + * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
| 1594 | + * @access private |
|
| 1595 | + * @param GF_Field[] $fields |
|
| 1596 | + * @param array $configured_fields |
|
| 1597 | + * @since 1.5 |
|
| 1598 | + * @return array $fields |
|
| 1599 | + */ |
|
| 1600 | + private function filter_fields( $fields, $configured_fields ) { |
|
| 1601 | + |
|
| 1602 | + if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1603 | + return $fields; |
|
| 1604 | + } |
|
| 1917 | 1605 | |
| 1918 | - // No errors; everything's fine here! |
|
| 1919 | - if( empty( $error ) ) { |
|
| 1920 | - return true; |
|
| 1921 | - } |
|
| 1606 | + $edit_fields = array(); |
|
| 1922 | 1607 | |
| 1923 | - if( $echo && $error !== true ) { |
|
| 1608 | + $field_type_blacklist = array( |
|
| 1609 | + 'page', |
|
| 1610 | + ); |
|
| 1924 | 1611 | |
| 1925 | - $error = esc_html( $error ); |
|
| 1612 | + /** |
|
| 1613 | + * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
| 1614 | + * @since 1.9.1 |
|
| 1615 | + * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
| 1616 | + */ |
|
| 1617 | + $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
| 1926 | 1618 | |
| 1927 | - /** |
|
| 1928 | - * @since 1.9 |
|
| 1929 | - */ |
|
| 1930 | - if ( ! empty( $this->entry ) ) { |
|
| 1931 | - $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;" ) ); |
|
| 1932 | - } |
|
| 1619 | + if( $hide_product_fields ) { |
|
| 1620 | + $field_type_blacklist[] = 'option'; |
|
| 1621 | + $field_type_blacklist[] = 'quantity'; |
|
| 1622 | + $field_type_blacklist[] = 'product'; |
|
| 1623 | + $field_type_blacklist[] = 'total'; |
|
| 1624 | + $field_type_blacklist[] = 'shipping'; |
|
| 1625 | + $field_type_blacklist[] = 'calculation'; |
|
| 1626 | + } |
|
| 1933 | 1627 | |
| 1934 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1935 | - } |
|
| 1628 | + // First, remove blacklist or calculation fields |
|
| 1629 | + foreach ( $fields as $key => $field ) { |
|
| 1936 | 1630 | |
| 1937 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1631 | + // Remove the fields that have calculation properties and keep them to be used later |
|
| 1632 | + // @since 1.16.2 |
|
| 1633 | + if( $field->has_calculation() ) { |
|
| 1634 | + $this->fields_with_calculation[] = $field; |
|
| 1635 | + // don't remove the calculation fields on form render. |
|
| 1636 | + } |
|
| 1938 | 1637 | |
| 1939 | - return false; |
|
| 1940 | - } |
|
| 1941 | - |
|
| 1942 | - |
|
| 1943 | - /** |
|
| 1944 | - * Check whether a field is editable by the current user, and optionally display an error message |
|
| 1945 | - * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
| 1946 | - * @param array $field Field or field settings array |
|
| 1947 | - * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
| 1948 | - * @return boolean True: user can edit the current field; False: nope, they can't. |
|
| 1949 | - */ |
|
| 1950 | - private function user_can_edit_field( $field, $echo = false ) { |
|
| 1638 | + // process total field after all fields have been saved |
|
| 1639 | + if ( $field->type == 'total' ) { |
|
| 1640 | + $this->total_fields[] = $field; |
|
| 1641 | + unset( $fields[ $key ] ); |
|
| 1642 | + } |
|
| 1951 | 1643 | |
| 1952 | - $error = NULL; |
|
| 1644 | + if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1645 | + unset( $fields[ $key ] ); |
|
| 1646 | + } |
|
| 1647 | + } |
|
| 1953 | 1648 | |
| 1954 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1955 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1956 | - } |
|
| 1649 | + // The Edit tab has not been configured, so we return all fields by default. |
|
| 1650 | + if( empty( $configured_fields ) ) { |
|
| 1651 | + return $fields; |
|
| 1652 | + } |
|
| 1957 | 1653 | |
| 1958 | - // No errors; everything's fine here! |
|
| 1959 | - if( empty( $error ) ) { |
|
| 1960 | - return true; |
|
| 1961 | - } |
|
| 1654 | + // The edit tab has been configured, so we loop through to configured settings |
|
| 1655 | + foreach ( $configured_fields as $configured_field ) { |
|
| 1962 | 1656 | |
| 1963 | - if( $echo ) { |
|
| 1964 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1965 | - } |
|
| 1966 | - |
|
| 1967 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1657 | + /** @var GF_Field $field */ |
|
| 1658 | + foreach ( $fields as $field ) { |
|
| 1968 | 1659 | |
| 1969 | - return false; |
|
| 1660 | + if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1661 | + $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1662 | + break; |
|
| 1663 | + } |
|
| 1970 | 1664 | |
| 1971 | - } |
|
| 1665 | + } |
|
| 1972 | 1666 | |
| 1667 | + } |
|
| 1973 | 1668 | |
| 1974 | - /** |
|
| 1975 | - * checks if user has permissions to edit a specific field |
|
| 1976 | - * |
|
| 1977 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
| 1978 | - * |
|
| 1979 | - * @param [type] $field [description] |
|
| 1980 | - * @return bool |
|
| 1981 | - */ |
|
| 1982 | - private function check_user_cap_edit_field( $field ) { |
|
| 1669 | + return $edit_fields; |
|
| 1983 | 1670 | |
| 1984 | - // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
| 1985 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1986 | - return true; |
|
| 1987 | - } |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + /** |
|
| 1674 | + * Override GF Form field properties with the ones defined on the View |
|
| 1675 | + * @param GF_Field $field GF Form field object |
|
| 1676 | + * @param array $field_setting GV field options |
|
| 1677 | + * @since 1.5 |
|
| 1678 | + * @return array|GF_Field |
|
| 1679 | + */ |
|
| 1680 | + private function merge_field_properties( $field, $field_setting ) { |
|
| 1681 | + |
|
| 1682 | + $return_field = $field; |
|
| 1683 | + |
|
| 1684 | + if( empty( $field_setting['show_label'] ) ) { |
|
| 1685 | + $return_field->label = ''; |
|
| 1686 | + } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1687 | + $return_field->label = $field_setting['custom_label']; |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1691 | + $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + /** |
|
| 1695 | + * Normalize page numbers - avoid conflicts with page validation |
|
| 1696 | + * @since 1.6 |
|
| 1697 | + */ |
|
| 1698 | + $return_field->pageNumber = 1; |
|
| 1699 | + |
|
| 1700 | + return $return_field; |
|
| 1701 | + |
|
| 1702 | + } |
|
| 1703 | + |
|
| 1704 | + /** |
|
| 1705 | + * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
| 1706 | + * |
|
| 1707 | + * @since 1.9.1 |
|
| 1708 | + * |
|
| 1709 | + * @param array|GF_Field[] $fields Gravity Forms form fields |
|
| 1710 | + * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1711 | + * @param array $form GF Form array |
|
| 1712 | + * @param int $view_id View ID |
|
| 1713 | + * |
|
| 1714 | + * @return array Possibly modified form array |
|
| 1715 | + */ |
|
| 1716 | + private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
| 1717 | + |
|
| 1718 | + /** |
|
| 1719 | + * @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 |
|
| 1720 | + * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1721 | + * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1722 | + * @since 1.9.1 |
|
| 1723 | + * @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. |
|
| 1724 | + * @param array $form GF Form array |
|
| 1725 | + * @param int $view_id View ID |
|
| 1726 | + */ |
|
| 1727 | + $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1728 | + |
|
| 1729 | + if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1730 | + foreach( $fields as $k => $field ) { |
|
| 1731 | + if( $field->adminOnly ) { |
|
| 1732 | + unset( $fields[ $k ] ); |
|
| 1733 | + } |
|
| 1734 | + } |
|
| 1735 | + return $fields; |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + foreach( $fields as &$field ) { |
|
| 1739 | + $field->adminOnly = false; |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + return $fields; |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + // --- Conditional Logic |
|
| 1746 | + |
|
| 1747 | + /** |
|
| 1748 | + * Conditional logic isn't designed to work with forms that already have content. When switching input values, |
|
| 1749 | + * the dependent fields will be blank. |
|
| 1750 | + * |
|
| 1751 | + * Note: This is because GF populates a JavaScript variable with the input values. This is tough to filter at the input level; |
|
| 1752 | + * via the `gform_field_value` filter; it requires lots of legwork. Doing it at the form level is easier. |
|
| 1753 | + * |
|
| 1754 | + * @since 1.17.4 |
|
| 1755 | + * |
|
| 1756 | + * @param array $form Gravity Forms array object |
|
| 1757 | + * |
|
| 1758 | + * @return array $form, modified to fix conditional |
|
| 1759 | + */ |
|
| 1760 | + function prefill_conditional_logic( $form ) { |
|
| 1761 | + |
|
| 1762 | + if( ! GFFormDisplay::has_conditional_logic( $form ) ) { |
|
| 1763 | + return $form; |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + // Have Conditional Logic pre-fill fields as if the data were default values |
|
| 1767 | + /** @var GF_Field $field */ |
|
| 1768 | + foreach ( $form['fields'] as &$field ) { |
|
| 1769 | + |
|
| 1770 | + if( 'checkbox' === $field->type ) { |
|
| 1771 | + foreach ( $field->get_entry_inputs() as $key => $input ) { |
|
| 1772 | + $input_id = $input['id']; |
|
| 1773 | + $choice = $field->choices[ $key ]; |
|
| 1774 | + $value = rgar( $this->entry, $input_id ); |
|
| 1775 | + $match = RGFormsModel::choice_value_match( $field, $choice, $value ); |
|
| 1776 | + if( $match ) { |
|
| 1777 | + $field->choices[ $key ]['isSelected'] = true; |
|
| 1778 | + } |
|
| 1779 | + } |
|
| 1780 | + } else { |
|
| 1781 | + |
|
| 1782 | + // We need to run through each field to set the default values |
|
| 1783 | + foreach ( $this->entry as $field_id => $field_value ) { |
|
| 1784 | + |
|
| 1785 | + if( floatval( $field_id ) === floatval( $field->id ) ) { |
|
| 1786 | + |
|
| 1787 | + if( 'list' === $field->type ) { |
|
| 1788 | + $list_rows = maybe_unserialize( $field_value ); |
|
| 1789 | + |
|
| 1790 | + $list_field_value = array(); |
|
| 1791 | + foreach ( $list_rows as $row ) { |
|
| 1792 | + foreach ( $row as $column ) { |
|
| 1793 | + $list_field_value[] = $column; |
|
| 1794 | + } |
|
| 1795 | + } |
|
| 1796 | + |
|
| 1797 | + $field->defaultValue = $list_field_value; |
|
| 1798 | + } else { |
|
| 1799 | + $field->defaultValue = $field_value; |
|
| 1800 | + } |
|
| 1801 | + } |
|
| 1802 | + } |
|
| 1803 | + } |
|
| 1804 | + } |
|
| 1805 | + |
|
| 1806 | + return $form; |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + /** |
|
| 1810 | + * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
| 1811 | + * |
|
| 1812 | + * @todo Merge with caller method |
|
| 1813 | + * @since 1.9 |
|
| 1814 | + * |
|
| 1815 | + * @param array $form Gravity Forms form |
|
| 1816 | + * @return array Modified form, if not using Conditional Logic |
|
| 1817 | + */ |
|
| 1818 | + private function filter_conditional_logic( $form ) { |
|
| 1819 | + |
|
| 1820 | + /** |
|
| 1821 | + * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
| 1822 | + * @since 1.9 |
|
| 1823 | + * @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 |
|
| 1824 | + * @param array $form Gravity Forms form |
|
| 1825 | + */ |
|
| 1826 | + $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
| 1827 | + |
|
| 1828 | + if( $use_conditional_logic ) { |
|
| 1829 | + return $form; |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + foreach( $form['fields'] as &$field ) { |
|
| 1833 | + /* @var GF_Field $field */ |
|
| 1834 | + $field->conditionalLogic = null; |
|
| 1835 | + } |
|
| 1836 | + |
|
| 1837 | + unset( $form['button']['conditionalLogic'] ); |
|
| 1838 | + |
|
| 1839 | + return $form; |
|
| 1840 | + |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + /** |
|
| 1844 | + * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
| 1845 | + * |
|
| 1846 | + * @since 1.9 |
|
| 1847 | + * |
|
| 1848 | + * @param $has_conditional_logic |
|
| 1849 | + * @param $form |
|
| 1850 | + * @return mixed|void |
|
| 1851 | + */ |
|
| 1852 | + public function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
| 1853 | + |
|
| 1854 | + if( ! $this->is_edit_entry() ) { |
|
| 1855 | + return $has_conditional_logic; |
|
| 1856 | + } |
|
| 1857 | + |
|
| 1858 | + /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */ |
|
| 1859 | + return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + // --- User checks and nonces |
|
| 1864 | + |
|
| 1865 | + /** |
|
| 1866 | + * Check if the user can edit the entry |
|
| 1867 | + * |
|
| 1868 | + * - Is the nonce valid? |
|
| 1869 | + * - Does the user have the right caps for the entry |
|
| 1870 | + * - Is the entry in the trash? |
|
| 1871 | + * |
|
| 1872 | + * @todo Move to GVCommon |
|
| 1873 | + * |
|
| 1874 | + * @param boolean $echo Show error messages in the form? |
|
| 1875 | + * @return boolean True: can edit form. False: nope. |
|
| 1876 | + */ |
|
| 1877 | + private function user_can_edit_entry( $echo = false ) { |
|
| 1878 | + |
|
| 1879 | + $error = NULL; |
|
| 1880 | + |
|
| 1881 | + /** |
|
| 1882 | + * 1. Permalinks are turned off |
|
| 1883 | + * 2. There are two entries embedded using oEmbed |
|
| 1884 | + * 3. One of the entries has just been saved |
|
| 1885 | + */ |
|
| 1886 | + if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1887 | + |
|
| 1888 | + $error = true; |
|
| 1889 | + |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1893 | + |
|
| 1894 | + $error = true; |
|
| 1895 | + |
|
| 1896 | + } elseif( ! $this->verify_nonce() ) { |
|
| 1897 | + |
|
| 1898 | + /** |
|
| 1899 | + * If the Entry is embedded, there may be two entries on the same page. |
|
| 1900 | + * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
| 1901 | + */ |
|
| 1902 | + if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1903 | + $error = true; |
|
| 1904 | + } else { |
|
| 1905 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1906 | + } |
|
| 1907 | + |
|
| 1908 | + } |
|
| 1909 | + |
|
| 1910 | + if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1911 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1912 | + } |
|
| 1913 | + |
|
| 1914 | + if( $this->entry['status'] === 'trash' ) { |
|
| 1915 | + $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1916 | + } |
|
| 1917 | + |
|
| 1918 | + // No errors; everything's fine here! |
|
| 1919 | + if( empty( $error ) ) { |
|
| 1920 | + return true; |
|
| 1921 | + } |
|
| 1922 | + |
|
| 1923 | + if( $echo && $error !== true ) { |
|
| 1924 | + |
|
| 1925 | + $error = esc_html( $error ); |
|
| 1926 | + |
|
| 1927 | + /** |
|
| 1928 | + * @since 1.9 |
|
| 1929 | + */ |
|
| 1930 | + if ( ! empty( $this->entry ) ) { |
|
| 1931 | + $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;" ) ); |
|
| 1932 | + } |
|
| 1988 | 1933 | |
| 1989 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1934 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1935 | + } |
|
| 1990 | 1936 | |
| 1991 | - // If the field has custom editing capaibilities set, check those |
|
| 1992 | - if( $field_cap ) { |
|
| 1993 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - return false; |
|
| 1997 | - } |
|
| 1937 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1998 | 1938 | |
| 1939 | + return false; |
|
| 1940 | + } |
|
| 1941 | + |
|
| 1942 | + |
|
| 1943 | + /** |
|
| 1944 | + * Check whether a field is editable by the current user, and optionally display an error message |
|
| 1945 | + * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
| 1946 | + * @param array $field Field or field settings array |
|
| 1947 | + * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
| 1948 | + * @return boolean True: user can edit the current field; False: nope, they can't. |
|
| 1949 | + */ |
|
| 1950 | + private function user_can_edit_field( $field, $echo = false ) { |
|
| 1951 | + |
|
| 1952 | + $error = NULL; |
|
| 1953 | + |
|
| 1954 | + if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1955 | + $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + // No errors; everything's fine here! |
|
| 1959 | + if( empty( $error ) ) { |
|
| 1960 | + return true; |
|
| 1961 | + } |
|
| 1962 | + |
|
| 1963 | + if( $echo ) { |
|
| 1964 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1965 | + } |
|
| 1966 | + |
|
| 1967 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1968 | + |
|
| 1969 | + return false; |
|
| 1970 | + |
|
| 1971 | + } |
|
| 1972 | + |
|
| 1973 | + |
|
| 1974 | + /** |
|
| 1975 | + * checks if user has permissions to edit a specific field |
|
| 1976 | + * |
|
| 1977 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
| 1978 | + * |
|
| 1979 | + * @param [type] $field [description] |
|
| 1980 | + * @return bool |
|
| 1981 | + */ |
|
| 1982 | + private function check_user_cap_edit_field( $field ) { |
|
| 1999 | 1983 | |
| 2000 | - /** |
|
| 2001 | - * Is the current nonce valid for editing the entry? |
|
| 2002 | - * @return boolean |
|
| 2003 | - */ |
|
| 2004 | - public function verify_nonce() { |
|
| 1984 | + // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
| 1985 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1986 | + return true; |
|
| 1987 | + } |
|
| 2005 | 1988 | |
| 2006 | - // Verify form submitted for editing single |
|
| 2007 | - if( $this->is_edit_entry_submission() ) { |
|
| 2008 | - $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
| 2009 | - } |
|
| 1989 | + $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 2010 | 1990 | |
| 2011 | - // Verify |
|
| 2012 | - else if( ! $this->is_edit_entry() ) { |
|
| 2013 | - $valid = false; |
|
| 2014 | - } |
|
| 1991 | + // If the field has custom editing capaibilities set, check those |
|
| 1992 | + if( $field_cap ) { |
|
| 1993 | + return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1994 | + } |
|
| 2015 | 1995 | |
| 2016 | - else { |
|
| 2017 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 2018 | - } |
|
| 1996 | + return false; |
|
| 1997 | + } |
|
| 2019 | 1998 | |
| 2020 | - /** |
|
| 2021 | - * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
| 2022 | - * @since 1.13 |
|
| 2023 | - * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
| 2024 | - * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
| 2025 | - */ |
|
| 2026 | - $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
| 2027 | 1999 | |
| 2028 | - return $valid; |
|
| 2029 | - } |
|
| 2000 | + /** |
|
| 2001 | + * Is the current nonce valid for editing the entry? |
|
| 2002 | + * @return boolean |
|
| 2003 | + */ |
|
| 2004 | + public function verify_nonce() { |
|
| 2005 | + |
|
| 2006 | + // Verify form submitted for editing single |
|
| 2007 | + if( $this->is_edit_entry_submission() ) { |
|
| 2008 | + $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
| 2009 | + } |
|
| 2010 | + |
|
| 2011 | + // Verify |
|
| 2012 | + else if( ! $this->is_edit_entry() ) { |
|
| 2013 | + $valid = false; |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + else { |
|
| 2017 | + $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 2018 | + } |
|
| 2019 | + |
|
| 2020 | + /** |
|
| 2021 | + * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
| 2022 | + * @since 1.13 |
|
| 2023 | + * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
| 2024 | + * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
| 2025 | + */ |
|
| 2026 | + $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
| 2027 | + |
|
| 2028 | + return $valid; |
|
| 2029 | + } |
|
| 2030 | 2030 | |
| 2031 | 2031 | |
| 2032 | 2032 | |
@@ -119,16 +119,16 @@ discard block |
||
| 119 | 119 | function load() { |
| 120 | 120 | |
| 121 | 121 | /** @define "GRAVITYVIEW_DIR" "../../../" */ |
| 122 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 122 | + include_once( GRAVITYVIEW_DIR . 'includes/class-admin-approve-entries.php' ); |
|
| 123 | 123 | |
| 124 | 124 | // Don't display an embedded form when editing an entry |
| 125 | 125 | add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
| 126 | 126 | add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
| 127 | 127 | |
| 128 | 128 | // Stop Gravity Forms processing what is ours! |
| 129 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 129 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form' ), 8 ); |
|
| 130 | 130 | |
| 131 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 131 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry' ) ); |
|
| 132 | 132 | |
| 133 | 133 | add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
| 134 | 134 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
| 140 | 140 | |
| 141 | 141 | // Add fields expected by GFFormDisplay::validate() |
| 142 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 142 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation' ) ); |
|
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | * @return void |
| 155 | 155 | */ |
| 156 | 156 | public function prevent_render_form() { |
| 157 | - if( $this->is_edit_entry() ) { |
|
| 158 | - if( 'wp_head' === current_filter() ) { |
|
| 157 | + if ( $this->is_edit_entry() ) { |
|
| 158 | + if ( 'wp_head' === current_filter() ) { |
|
| 159 | 159 | add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
| 160 | 160 | } else { |
| 161 | 161 | remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function prevent_maybe_process_form() { |
| 172 | 172 | |
| 173 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 173 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 174 | 174 | |
| 175 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 176 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 175 | + if ( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 176 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form' ), 9 ); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public function is_edit_entry() { |
| 185 | 185 | |
| 186 | - $is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] ); |
|
| 186 | + $is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET[ 'edit' ] ); |
|
| 187 | 187 | |
| 188 | 188 | return ( $is_edit_entry || $this->is_edit_entry_submission() ); |
| 189 | 189 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * @return boolean |
| 195 | 195 | */ |
| 196 | 196 | public function is_edit_entry_submission() { |
| 197 | - return !empty( $_POST[ self::$nonce_field ] ); |
|
| 197 | + return ! empty( $_POST[ self::$nonce_field ] ); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -205,15 +205,15 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | |
| 207 | 207 | $entries = $gravityview_view->getEntries(); |
| 208 | - self::$original_entry = $entries[0]; |
|
| 209 | - $this->entry = $entries[0]; |
|
| 208 | + self::$original_entry = $entries[ 0 ]; |
|
| 209 | + $this->entry = $entries[ 0 ]; |
|
| 210 | 210 | |
| 211 | 211 | self::$original_form = $gravityview_view->getForm(); |
| 212 | 212 | $this->form = $gravityview_view->getForm(); |
| 213 | 213 | $this->form_id = $gravityview_view->getFormId(); |
| 214 | 214 | $this->view_id = $gravityview_view->getViewId(); |
| 215 | 215 | |
| 216 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 216 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry[ 'id' ] ); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | $this->setup_vars(); |
| 234 | 234 | |
| 235 | 235 | // Multiple Views embedded, don't proceed if nonce fails |
| 236 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 237 | - do_action('gravityview_log_error', __METHOD__ . ': Nonce validation failed for the Edit Entry request; returning' ); |
|
| 236 | + if ( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ) ) { |
|
| 237 | + do_action( 'gravityview_log_error', __METHOD__ . ': Nonce validation failed for the Edit Entry request; returning' ); |
|
| 238 | 238 | return; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // Sorry, you're not allowed here. |
| 242 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
| 243 | - do_action('gravityview_log_error', __METHOD__ . ': User is not allowed to edit this entry; returning', $this->entry ); |
|
| 242 | + if ( false === $this->user_can_edit_entry( true ) ) { |
|
| 243 | + do_action( 'gravityview_log_error', __METHOD__ . ': User is not allowed to edit this entry; returning', $this->entry ); |
|
| 244 | 244 | return; |
| 245 | 245 | } |
| 246 | 246 | |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | private function print_scripts() { |
| 261 | 261 | $gravityview_view = GravityView_View::getInstance(); |
| 262 | 262 | |
| 263 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 263 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url() . '/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 264 | 264 | |
| 265 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 265 | + GFFormDisplay::enqueue_form_scripts( $gravityview_view->getForm(), false ); |
|
| 266 | 266 | |
| 267 | 267 | // Sack is required for images |
| 268 | 268 | wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
@@ -274,32 +274,32 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | private function process_save() { |
| 276 | 276 | |
| 277 | - if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) { |
|
| 277 | + if ( empty( $_POST ) || ! isset( $_POST[ 'lid' ] ) ) { |
|
| 278 | 278 | return; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Make sure the entry, view, and form IDs are all correct |
| 282 | 282 | $valid = $this->verify_nonce(); |
| 283 | 283 | |
| 284 | - if( !$valid ) { |
|
| 285 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 284 | + if ( ! $valid ) { |
|
| 285 | + do_action( 'gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 286 | 286 | return; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 290 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 289 | + if ( $this->entry[ 'id' ] !== $_POST[ 'lid' ] ) { |
|
| 290 | + do_action( 'gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - do_action('gravityview_log_debug', __METHOD__ . ': $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 294 | + do_action( 'gravityview_log_debug', __METHOD__ . ': $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 295 | 295 | |
| 296 | 296 | $this->process_save_process_files( $this->form_id ); |
| 297 | 297 | |
| 298 | 298 | $this->validate(); |
| 299 | 299 | |
| 300 | - if( $this->is_valid ) { |
|
| 300 | + if ( $this->is_valid ) { |
|
| 301 | 301 | |
| 302 | - do_action('gravityview_log_debug', __METHOD__ . ': Submission is valid.' ); |
|
| 302 | + do_action( 'gravityview_log_debug', __METHOD__ . ': Submission is valid.' ); |
|
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | 305 | * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields |
@@ -309,22 +309,22 @@ discard block |
||
| 309 | 309 | /** |
| 310 | 310 | * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
| 311 | 311 | */ |
| 312 | - unset( $_GET['page'] ); |
|
| 312 | + unset( $_GET[ 'page' ] ); |
|
| 313 | 313 | |
| 314 | - $date_created = $this->entry['date_created']; |
|
| 314 | + $date_created = $this->entry[ 'date_created' ]; |
|
| 315 | 315 | |
| 316 | 316 | /** |
| 317 | 317 | * @hack to force Gravity Forms to use $read_value_from_post in GFFormsModel::save_lead() |
| 318 | 318 | * @since 1.17.2 |
| 319 | 319 | */ |
| 320 | - unset( $this->entry['date_created'] ); |
|
| 320 | + unset( $this->entry[ 'date_created' ] ); |
|
| 321 | 321 | |
| 322 | 322 | GFFormsModel::save_lead( $form, $this->entry ); |
| 323 | 323 | |
| 324 | 324 | // Delete the values for hidden inputs |
| 325 | 325 | $this->unset_hidden_field_values(); |
| 326 | 326 | |
| 327 | - $this->entry['date_created'] = $date_created; |
|
| 327 | + $this->entry[ 'date_created' ] = $date_created; |
|
| 328 | 328 | |
| 329 | 329 | // Process calculation fields |
| 330 | 330 | $this->update_calculation_fields(); |
@@ -343,10 +343,10 @@ discard block |
||
| 343 | 343 | * @param array $form Gravity Forms form array |
| 344 | 344 | * @param string $entry_id Numeric ID of the entry that was updated |
| 345 | 345 | */ |
| 346 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 346 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry[ 'id' ] ); |
|
| 347 | 347 | |
| 348 | 348 | } else { |
| 349 | - do_action('gravityview_log_error', __METHOD__ . ': Submission is NOT valid.', $this->entry ); |
|
| 349 | + do_action( 'gravityview_log_error', __METHOD__ . ': Submission is NOT valid.', $this->entry ); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | } // process_save |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | private function unset_hidden_field_values() { |
| 364 | 364 | global $wpdb; |
| 365 | 365 | |
| 366 | - $lead_detail_table = GFFormsModel::get_lead_details_table_name(); |
|
| 367 | - $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) ); |
|
| 366 | + $lead_detail_table = GFFormsModel::get_lead_details_table_name(); |
|
| 367 | + $current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry[ 'id' ] ) ); |
|
| 368 | 368 | |
| 369 | 369 | foreach ( $this->entry as $input_id => $field_value ) { |
| 370 | 370 | |
@@ -417,11 +417,11 @@ discard block |
||
| 417 | 417 | * @return mixed |
| 418 | 418 | */ |
| 419 | 419 | public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
| 420 | - if( ! $this->is_edit_entry() ) { |
|
| 420 | + if ( ! $this->is_edit_entry() ) { |
|
| 421 | 421 | return $plupload_init; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - $plupload_init['gf_vars']['max_files'] = 0; |
|
| 424 | + $plupload_init[ 'gf_vars' ][ 'max_files' ] = 0; |
|
| 425 | 425 | |
| 426 | 426 | return $plupload_init; |
| 427 | 427 | } |
@@ -436,22 +436,22 @@ discard block |
||
| 436 | 436 | $form = $this->form; |
| 437 | 437 | |
| 438 | 438 | /** @var GF_Field $field */ |
| 439 | - foreach( $form['fields'] as $k => &$field ) { |
|
| 439 | + foreach ( $form[ 'fields' ] as $k => &$field ) { |
|
| 440 | 440 | |
| 441 | 441 | /** |
| 442 | 442 | * Remove the fields with calculation formulas before save to avoid conflicts with GF logic |
| 443 | 443 | * @since 1.16.3 |
| 444 | 444 | * @var GF_Field $field |
| 445 | 445 | */ |
| 446 | - if( $field->has_calculation() ) { |
|
| 447 | - unset( $form['fields'][ $k ] ); |
|
| 446 | + if ( $field->has_calculation() ) { |
|
| 447 | + unset( $form[ 'fields' ][ $k ] ); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | $field->adminOnly = false; |
| 451 | 451 | |
| 452 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 453 | - foreach( $field->inputs as $key => $input ) { |
|
| 454 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 452 | + if ( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 453 | + foreach ( $field->inputs as $key => $input ) { |
|
| 454 | + $field->inputs[ $key ][ 'id' ] = (string)$input[ 'id' ]; |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | } |
@@ -465,20 +465,20 @@ discard block |
||
| 465 | 465 | $update = false; |
| 466 | 466 | |
| 467 | 467 | // get the most up to date entry values |
| 468 | - $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 468 | + $entry = GFAPI::get_entry( $this->entry[ 'id' ] ); |
|
| 469 | 469 | |
| 470 | - if( !empty( $this->fields_with_calculation ) ) { |
|
| 470 | + if ( ! empty( $this->fields_with_calculation ) ) { |
|
| 471 | 471 | $update = true; |
| 472 | 472 | foreach ( $this->fields_with_calculation as $calc_field ) { |
| 473 | 473 | $inputs = $calc_field->get_entry_inputs(); |
| 474 | 474 | if ( is_array( $inputs ) ) { |
| 475 | 475 | foreach ( $inputs as $input ) { |
| 476 | - $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 477 | - $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 476 | + $input_name = 'input_' . str_replace( '.', '_', $input[ 'id' ] ); |
|
| 477 | + $entry[ strval( $input[ 'id' ] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry[ 'id' ], $entry ); |
|
| 478 | 478 | } |
| 479 | 479 | } else { |
| 480 | - $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 481 | - $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 480 | + $input_name = 'input_' . str_replace( '.', '_', $calc_field->id ); |
|
| 481 | + $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry[ 'id' ], $entry ); |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | |
@@ -488,16 +488,16 @@ discard block |
||
| 488 | 488 | if ( ! empty( $this->total_fields ) ) { |
| 489 | 489 | $update = true; |
| 490 | 490 | foreach ( $this->total_fields as $total_field ) { |
| 491 | - $input_name = 'input_' . str_replace( '.', '_', $total_field->id); |
|
| 492 | - $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry ); |
|
| 491 | + $input_name = 'input_' . str_replace( '.', '_', $total_field->id ); |
|
| 492 | + $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry[ 'id' ], $entry ); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - if( $update ) { |
|
| 496 | + if ( $update ) { |
|
| 497 | 497 | |
| 498 | 498 | $return_entry = GFAPI::update_entry( $entry ); |
| 499 | 499 | |
| 500 | - if( is_wp_error( $return_entry ) ) { |
|
| 500 | + if ( is_wp_error( $return_entry ) ) { |
|
| 501 | 501 | do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry ); |
| 502 | 502 | } else { |
| 503 | 503 | do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' ); |
@@ -528,18 +528,18 @@ discard block |
||
| 528 | 528 | |
| 529 | 529 | $input_name = 'input_' . $field_id; |
| 530 | 530 | |
| 531 | - if ( !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 531 | + if ( ! empty( $_FILES[ $input_name ][ 'name' ] ) ) { |
|
| 532 | 532 | |
| 533 | 533 | // We have a new image |
| 534 | 534 | |
| 535 | - $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
|
| 535 | + $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ] ); |
|
| 536 | 536 | |
| 537 | 537 | $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
| 538 | 538 | $img_url = rgar( $ary, 0 ); |
| 539 | 539 | |
| 540 | - $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
|
| 541 | - $img_caption = count( $ary ) > 2 ? $ary[2] : ''; |
|
| 542 | - $img_description = count( $ary ) > 3 ? $ary[3] : ''; |
|
| 540 | + $img_title = count( $ary ) > 1 ? $ary[ 1 ] : ''; |
|
| 541 | + $img_caption = count( $ary ) > 2 ? $ary[ 2 ] : ''; |
|
| 542 | + $img_description = count( $ary ) > 3 ? $ary[ 3 ] : ''; |
|
| 543 | 543 | |
| 544 | 544 | $image_meta = array( |
| 545 | 545 | 'post_excerpt' => $img_caption, |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | |
| 549 | 549 | //adding title only if it is not empty. It will default to the file name if it is not in the array |
| 550 | 550 | if ( ! empty( $img_title ) ) { |
| 551 | - $image_meta['post_title'] = $img_title; |
|
| 551 | + $image_meta[ 'post_title' ] = $img_title; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
@@ -563,22 +563,22 @@ discard block |
||
| 563 | 563 | set_post_thumbnail( $post_id, $media_id ); |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 566 | + } elseif ( ! empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 567 | 567 | |
| 568 | 568 | // Same image although the image title, caption or description might have changed |
| 569 | 569 | |
| 570 | 570 | $ary = array(); |
| 571 | - if( ! empty( $entry[ $field_id ] ) ) { |
|
| 571 | + if ( ! empty( $entry[ $field_id ] ) ) { |
|
| 572 | 572 | $ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] ); |
| 573 | 573 | } |
| 574 | 574 | $img_url = rgar( $ary, 0 ); |
| 575 | 575 | |
| 576 | 576 | // is this really the same image or something went wrong ? |
| 577 | - if( $img_url === $_POST[ $input_name ] ) { |
|
| 577 | + if ( $img_url === $_POST[ $input_name ] ) { |
|
| 578 | 578 | |
| 579 | - $img_title = rgar( $value, $field_id .'.1' ); |
|
| 580 | - $img_caption = rgar( $value, $field_id .'.4' ); |
|
| 581 | - $img_description = rgar( $value, $field_id .'.7' ); |
|
| 579 | + $img_title = rgar( $value, $field_id . '.1' ); |
|
| 580 | + $img_caption = rgar( $value, $field_id . '.4' ); |
|
| 581 | + $img_description = rgar( $value, $field_id . '.7' ); |
|
| 582 | 582 | |
| 583 | 583 | $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; |
| 584 | 584 | |
@@ -618,16 +618,16 @@ discard block |
||
| 618 | 618 | */ |
| 619 | 619 | private function maybe_update_post_fields( $form ) { |
| 620 | 620 | |
| 621 | - if( empty( $this->entry['post_id'] ) ) { |
|
| 621 | + if ( empty( $this->entry[ 'post_id' ] ) ) { |
|
| 622 | 622 | do_action( 'gravityview_log_debug', __METHOD__ . ': This entry has no post fields. Continuing...' ); |
| 623 | 623 | return; |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | - $post_id = $this->entry['post_id']; |
|
| 626 | + $post_id = $this->entry[ 'post_id' ]; |
|
| 627 | 627 | |
| 628 | 628 | // Security check |
| 629 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 630 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 629 | + if ( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 630 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id ); |
|
| 631 | 631 | return; |
| 632 | 632 | } |
| 633 | 633 | |
@@ -639,25 +639,25 @@ discard block |
||
| 639 | 639 | |
| 640 | 640 | $field = RGFormsModel::get_field( $form, $field_id ); |
| 641 | 641 | |
| 642 | - if( ! $field ) { |
|
| 642 | + if ( ! $field ) { |
|
| 643 | 643 | continue; |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) { |
|
| 646 | + if ( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) { |
|
| 647 | 647 | |
| 648 | 648 | // Get the value of the field, including $_POSTed value |
| 649 | 649 | $value = RGFormsModel::get_field_value( $field ); |
| 650 | 650 | |
| 651 | 651 | // Use temporary entry variable, to make values available to fill_post_template() and update_post_image() |
| 652 | 652 | $entry_tmp = $this->entry; |
| 653 | - $entry_tmp["{$field_id}"] = $value; |
|
| 653 | + $entry_tmp[ "{$field_id}" ] = $value; |
|
| 654 | 654 | |
| 655 | - switch( $field->type ) { |
|
| 655 | + switch ( $field->type ) { |
|
| 656 | 656 | |
| 657 | 657 | case 'post_title': |
| 658 | 658 | $post_title = $value; |
| 659 | - if( rgar( $form, 'postTitleTemplateEnabled' ) ) { |
|
| 660 | - $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp ); |
|
| 659 | + if ( rgar( $form, 'postTitleTemplateEnabled' ) ) { |
|
| 660 | + $post_title = $this->fill_post_template( $form[ 'postTitleTemplate' ], $form, $entry_tmp ); |
|
| 661 | 661 | } |
| 662 | 662 | $updated_post->post_title = $post_title; |
| 663 | 663 | $updated_post->post_name = $post_title; |
@@ -666,8 +666,8 @@ discard block |
||
| 666 | 666 | |
| 667 | 667 | case 'post_content': |
| 668 | 668 | $post_content = $value; |
| 669 | - if( rgar( $form, 'postContentTemplateEnabled' ) ) { |
|
| 670 | - $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true ); |
|
| 669 | + if ( rgar( $form, 'postContentTemplateEnabled' ) ) { |
|
| 670 | + $post_content = $this->fill_post_template( $form[ 'postContentTemplate' ], $form, $entry_tmp, true ); |
|
| 671 | 671 | } |
| 672 | 672 | $updated_post->post_content = $post_content; |
| 673 | 673 | unset( $post_content ); |
@@ -681,12 +681,12 @@ discard block |
||
| 681 | 681 | case 'post_category': |
| 682 | 682 | break; |
| 683 | 683 | case 'post_custom_field': |
| 684 | - if( ! empty( $field->customFieldTemplateEnabled ) ) { |
|
| 684 | + if ( ! empty( $field->customFieldTemplateEnabled ) ) { |
|
| 685 | 685 | $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true ); |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) { |
| 689 | - $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 689 | + $value = function_exists( 'wp_json_encode' ) ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | update_post_meta( $post_id, $field->postCustomFieldName, $value ); |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | // update entry after |
| 703 | - $this->entry["{$field_id}"] = $value; |
|
| 703 | + $this->entry[ "{$field_id}" ] = $value; |
|
| 704 | 704 | |
| 705 | 705 | $update_entry = true; |
| 706 | 706 | |
@@ -709,25 +709,25 @@ discard block |
||
| 709 | 709 | |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - if( $update_entry ) { |
|
| 712 | + if ( $update_entry ) { |
|
| 713 | 713 | |
| 714 | 714 | $return_entry = GFAPI::update_entry( $this->entry ); |
| 715 | 715 | |
| 716 | - if( is_wp_error( $return_entry ) ) { |
|
| 716 | + if ( is_wp_error( $return_entry ) ) { |
|
| 717 | 717 | do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) ); |
| 718 | 718 | } else { |
| 719 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 719 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded' ); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | $return_post = wp_update_post( $updated_post, true ); |
| 725 | 725 | |
| 726 | - if( is_wp_error( $return_post ) ) { |
|
| 726 | + if ( is_wp_error( $return_post ) ) { |
|
| 727 | 727 | $return_post->add_data( $updated_post, '$updated_post' ); |
| 728 | 728 | do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) ); |
| 729 | 729 | } else { |
| 730 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); |
|
| 730 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded', $updated_post ); |
|
| 731 | 731 | } |
| 732 | 732 | } |
| 733 | 733 | |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | $input_type = RGFormsModel::get_input_type( $field ); |
| 746 | 746 | |
| 747 | 747 | // Only certain custom field types are supported |
| 748 | - switch( $input_type ) { |
|
| 748 | + switch ( $input_type ) { |
|
| 749 | 749 | case 'fileupload': |
| 750 | 750 | case 'list': |
| 751 | 751 | case 'multiselect': |
@@ -782,7 +782,7 @@ discard block |
||
| 782 | 782 | $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false ); |
| 783 | 783 | |
| 784 | 784 | // replace conditional shortcodes |
| 785 | - if( $do_shortcode ) { |
|
| 785 | + if ( $do_shortcode ) { |
|
| 786 | 786 | $output = do_shortcode( $output ); |
| 787 | 787 | } |
| 788 | 788 | |
@@ -801,18 +801,18 @@ discard block |
||
| 801 | 801 | */ |
| 802 | 802 | private function after_update() { |
| 803 | 803 | |
| 804 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry ); |
|
| 805 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 804 | + do_action( 'gform_after_update_entry', $this->form, $this->entry[ 'id' ], self::$original_entry ); |
|
| 805 | + do_action( "gform_after_update_entry_{$this->form[ 'id' ]}", $this->form, $this->entry[ 'id' ] ); |
|
| 806 | 806 | |
| 807 | 807 | // Re-define the entry now that we've updated it. |
| 808 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 808 | + $entry = RGFormsModel::get_lead( $this->entry[ 'id' ] ); |
|
| 809 | 809 | |
| 810 | 810 | $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
| 811 | 811 | |
| 812 | 812 | // We need to clear the cache because Gravity Forms caches the field values, which |
| 813 | 813 | // we have just updated. |
| 814 | - foreach ($this->form['fields'] as $key => $field) { |
|
| 815 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 814 | + foreach ( $this->form[ 'fields' ] as $key => $field ) { |
|
| 815 | + GFFormsModel::refresh_lead_field_value( $entry[ 'id' ], $field->id ); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | $this->entry = $entry; |
@@ -830,7 +830,7 @@ discard block |
||
| 830 | 830 | |
| 831 | 831 | <div class="gv-edit-entry-wrapper"><?php |
| 832 | 832 | |
| 833 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 833 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/inline-javascript.php', $this ); |
|
| 834 | 834 | |
| 835 | 835 | /** |
| 836 | 836 | * Fixes weird wpautop() issue |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | * @param string $edit_entry_title Modify the "Edit Entry" title |
| 847 | 847 | * @param GravityView_Edit_Entry_Render $this This object |
| 848 | 848 | */ |
| 849 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 849 | + $edit_entry_title = apply_filters( 'gravityview_edit_entry_title', __( 'Edit Entry', 'gravityview' ), $this ); |
|
| 850 | 850 | |
| 851 | 851 | echo esc_attr( $edit_entry_title ); |
| 852 | 852 | ?></span> |
@@ -892,20 +892,20 @@ discard block |
||
| 892 | 892 | */ |
| 893 | 893 | private function maybe_print_message() { |
| 894 | 894 | |
| 895 | - if( rgpost('action') === 'update' ) { |
|
| 895 | + if ( rgpost( 'action' ) === 'update' ) { |
|
| 896 | 896 | |
| 897 | 897 | $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
| 898 | 898 | |
| 899 | - if( ! $this->is_valid ){ |
|
| 899 | + if ( ! $this->is_valid ) { |
|
| 900 | 900 | |
| 901 | 901 | // Keeping this compatible with Gravity Forms. |
| 902 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 903 | - $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 902 | + $validation_message = "<div class='validation_error'>" . __( 'There was a problem with your submission.', 'gravityview' ) . " " . __( 'Errors have been highlighted below.', 'gravityview' ) . "</div>"; |
|
| 903 | + $message = apply_filters( "gform_validation_message_{$this->form[ 'id' ]}", apply_filters( "gform_validation_message", $validation_message, $this->form ), $this->form ); |
|
| 904 | 904 | |
| 905 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 905 | + echo GVCommon::generate_notice( $message, 'gv-error' ); |
|
| 906 | 906 | |
| 907 | 907 | } else { |
| 908 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 908 | + $entry_updated_message = sprintf( esc_attr__( 'Entry Updated. %sReturn to Entry%s', 'gravityview' ), '<a href="' . $back_link . '">', '</a>' ); |
|
| 909 | 909 | |
| 910 | 910 | /** |
| 911 | 911 | * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | * @param array $entry Gravity Forms entry array |
| 916 | 916 | * @param string $back_link URL to return to the original entry. @since 1.6 |
| 917 | 917 | */ |
| 918 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 918 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry, $back_link ); |
|
| 919 | 919 | |
| 920 | 920 | echo GVCommon::generate_notice( $message ); |
| 921 | 921 | } |
@@ -939,22 +939,22 @@ discard block |
||
| 939 | 939 | */ |
| 940 | 940 | do_action( 'gravityview/edit-entry/render/before', $this ); |
| 941 | 941 | |
| 942 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 943 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 942 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000, 3 ); |
|
| 943 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 944 | 944 | add_filter( 'gform_disable_view_counter', '__return_true' ); |
| 945 | 945 | |
| 946 | 946 | add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); |
| 947 | 947 | add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
| 948 | 948 | |
| 949 | 949 | // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
| 950 | - unset( $_GET['page'] ); |
|
| 950 | + unset( $_GET[ 'page' ] ); |
|
| 951 | 951 | |
| 952 | 952 | // TODO: Verify multiple-page forms |
| 953 | 953 | // TODO: Product fields are not editable |
| 954 | 954 | |
| 955 | 955 | ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic |
| 956 | 956 | |
| 957 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 957 | + $html = GFFormDisplay::get_form( $this->form[ 'id' ], false, false, true, $this->entry ); |
|
| 958 | 958 | |
| 959 | 959 | ob_get_clean(); |
| 960 | 960 | |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | * @return string |
| 981 | 981 | */ |
| 982 | 982 | public function render_form_buttons() { |
| 983 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 983 | + return gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/form-buttons.php', $this ); |
|
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | |
@@ -1000,10 +1000,10 @@ discard block |
||
| 1000 | 1000 | public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
| 1001 | 1001 | |
| 1002 | 1002 | // In case we have validated the form, use it to inject the validation results into the form render |
| 1003 | - if( isset( $this->form_after_validation ) ) { |
|
| 1003 | + if ( isset( $this->form_after_validation ) ) { |
|
| 1004 | 1004 | $form = $this->form_after_validation; |
| 1005 | 1005 | } else { |
| 1006 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 1006 | + $form[ 'fields' ] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | $form = $this->filter_conditional_logic( $form ); |
@@ -1011,8 +1011,8 @@ discard block |
||
| 1011 | 1011 | $form = $this->prefill_conditional_logic( $form ); |
| 1012 | 1012 | |
| 1013 | 1013 | // for now we don't support Save and Continue feature. |
| 1014 | - if( ! self::$supports_save_and_continue ) { |
|
| 1015 | - unset( $form['save'] ); |
|
| 1014 | + if ( ! self::$supports_save_and_continue ) { |
|
| 1015 | + unset( $form[ 'save' ] ); |
|
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | return $form; |
@@ -1033,29 +1033,29 @@ discard block |
||
| 1033 | 1033 | */ |
| 1034 | 1034 | public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
| 1035 | 1035 | |
| 1036 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 1036 | + if ( GFCommon::is_post_field( $field ) ) { |
|
| 1037 | 1037 | |
| 1038 | 1038 | $message = null; |
| 1039 | 1039 | |
| 1040 | 1040 | // First, make sure they have the capability to edit the post. |
| 1041 | - if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { |
|
| 1041 | + if ( false === current_user_can( 'edit_post', $this->entry[ 'post_id' ] ) ) { |
|
| 1042 | 1042 | |
| 1043 | 1043 | /** |
| 1044 | 1044 | * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post |
| 1045 | 1045 | * @param string $message The existing "You don't have permission..." text |
| 1046 | 1046 | */ |
| 1047 | - $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); |
|
| 1047 | + $message = apply_filters( 'gravityview/edit_entry/unsupported_post_field_text', __( 'You don’t have permission to edit this post.', 'gravityview' ) ); |
|
| 1048 | 1048 | |
| 1049 | - } elseif( null === get_post( $this->entry['post_id'] ) ) { |
|
| 1049 | + } elseif ( null === get_post( $this->entry[ 'post_id' ] ) ) { |
|
| 1050 | 1050 | /** |
| 1051 | 1051 | * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists |
| 1052 | 1052 | * @param string $message The existing "This field is not editable; the post no longer exists." text |
| 1053 | 1053 | */ |
| 1054 | - $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 1054 | + $message = apply_filters( 'gravityview/edit_entry/no_post_text', __( 'This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | - if( $message ) { |
|
| 1058 | - $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 1057 | + if ( $message ) { |
|
| 1058 | + $field_content = sprintf( '<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | } |
| 1061 | 1061 | |
@@ -1080,8 +1080,8 @@ discard block |
||
| 1080 | 1080 | |
| 1081 | 1081 | // If the form has been submitted, then we don't need to pre-fill the values, |
| 1082 | 1082 | // Except for fileupload type and when a field input is overridden- run always!! |
| 1083 | - if( |
|
| 1084 | - ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 1083 | + if ( |
|
| 1084 | + ( $this->is_edit_entry_submission() && ! in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 1085 | 1085 | && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) |
| 1086 | 1086 | || ! empty( $field_content ) |
| 1087 | 1087 | || in_array( $field->type, array( 'honeypot' ) ) |
@@ -1091,8 +1091,8 @@ discard block |
||
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | // Turn on Admin-style display for file upload fields only |
| 1094 | - if( 'fileupload' === $field->type ) { |
|
| 1095 | - $_GET['page'] = 'gf_entries'; |
|
| 1094 | + if ( 'fileupload' === $field->type ) { |
|
| 1095 | + $_GET[ 'page' ] = 'gf_entries'; |
|
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
@@ -1119,13 +1119,13 @@ discard block |
||
| 1119 | 1119 | * @param mixed $field_value field value used to populate the input |
| 1120 | 1120 | * @param GF_Field $field Gravity Forms field object |
| 1121 | 1121 | */ |
| 1122 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field ); |
|
| 1122 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type, $field_value, $field ); |
|
| 1123 | 1123 | |
| 1124 | 1124 | // Prevent any PHP warnings, like undefined index |
| 1125 | 1125 | ob_start(); |
| 1126 | 1126 | |
| 1127 | 1127 | /** @var GravityView_Field $gv_field */ |
| 1128 | - if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1128 | + if ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1129 | 1129 | $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
| 1130 | 1130 | } else { |
| 1131 | 1131 | $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | // If there was output, it's an error |
| 1136 | 1136 | $warnings = ob_get_clean(); |
| 1137 | 1137 | |
| 1138 | - if( !empty( $warnings ) ) { |
|
| 1138 | + if ( ! empty( $warnings ) ) { |
|
| 1139 | 1139 | do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
| 1140 | 1140 | } |
| 1141 | 1141 | |
@@ -1144,7 +1144,7 @@ discard block |
||
| 1144 | 1144 | * We need the fileupload html field to render with the proper id |
| 1145 | 1145 | * ( <li id="field_80_16" ... > ) |
| 1146 | 1146 | */ |
| 1147 | - unset( $_GET['page'] ); |
|
| 1147 | + unset( $_GET[ 'page' ] ); |
|
| 1148 | 1148 | |
| 1149 | 1149 | return $return; |
| 1150 | 1150 | } |
@@ -1167,7 +1167,7 @@ discard block |
||
| 1167 | 1167 | $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
| 1168 | 1168 | |
| 1169 | 1169 | // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
| 1170 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1170 | + if ( isset( $field->inputs ) && is_array( $field->inputs ) && ! in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1171 | 1171 | |
| 1172 | 1172 | $field_value = array(); |
| 1173 | 1173 | |
@@ -1176,10 +1176,10 @@ discard block |
||
| 1176 | 1176 | |
| 1177 | 1177 | foreach ( (array)$field->inputs as $input ) { |
| 1178 | 1178 | |
| 1179 | - $input_id = strval( $input['id'] ); |
|
| 1179 | + $input_id = strval( $input[ 'id' ] ); |
|
| 1180 | 1180 | |
| 1181 | 1181 | if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
| 1182 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1182 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1183 | 1183 | $allow_pre_populated = false; |
| 1184 | 1184 | } |
| 1185 | 1185 | |
@@ -1187,7 +1187,7 @@ discard block |
||
| 1187 | 1187 | |
| 1188 | 1188 | $pre_value = $field->get_value_submission( array(), false ); |
| 1189 | 1189 | |
| 1190 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1190 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && ! gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1191 | 1191 | |
| 1192 | 1192 | } else { |
| 1193 | 1193 | |
@@ -1198,13 +1198,13 @@ discard block |
||
| 1198 | 1198 | |
| 1199 | 1199 | // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
| 1200 | 1200 | // or pre-populated value if not empty and set to override saved value |
| 1201 | - $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1201 | + $field_value = ! gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && ! gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1202 | 1202 | |
| 1203 | 1203 | // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
| 1204 | - if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
|
| 1204 | + if ( 'post_category' === $field->type && ! gv_empty( $field_value, false, false ) ) { |
|
| 1205 | 1205 | $categories = array(); |
| 1206 | 1206 | foreach ( explode( ',', $field_value ) as $cat_string ) { |
| 1207 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1207 | + $categories[ ] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
| 1210 | 1210 | } |
@@ -1229,12 +1229,12 @@ discard block |
||
| 1229 | 1229 | */ |
| 1230 | 1230 | public function gform_pre_validation( $form ) { |
| 1231 | 1231 | |
| 1232 | - if( ! $this->verify_nonce() ) { |
|
| 1232 | + if ( ! $this->verify_nonce() ) { |
|
| 1233 | 1233 | return $form; |
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | 1236 | // Fix PHP warning regarding undefined index. |
| 1237 | - foreach ( $form['fields'] as &$field) { |
|
| 1237 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 1238 | 1238 | |
| 1239 | 1239 | // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
| 1240 | 1240 | // expects certain field array items to be set. |
@@ -1247,7 +1247,7 @@ discard block |
||
| 1247 | 1247 | $field['emailConfirmEnabled'] = ''; |
| 1248 | 1248 | }*/ |
| 1249 | 1249 | |
| 1250 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 1250 | + switch ( RGFormsModel::get_input_type( $field ) ) { |
|
| 1251 | 1251 | |
| 1252 | 1252 | /** |
| 1253 | 1253 | * 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. |
@@ -1261,37 +1261,37 @@ discard block |
||
| 1261 | 1261 | // Set the previous value |
| 1262 | 1262 | $entry = $this->get_entry(); |
| 1263 | 1263 | |
| 1264 | - $input_name = 'input_'.$field->id; |
|
| 1265 | - $form_id = $form['id']; |
|
| 1264 | + $input_name = 'input_' . $field->id; |
|
| 1265 | + $form_id = $form[ 'id' ]; |
|
| 1266 | 1266 | |
| 1267 | 1267 | $value = NULL; |
| 1268 | 1268 | |
| 1269 | 1269 | // Use the previous entry value as the default. |
| 1270 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1270 | + if ( isset( $entry[ $field->id ] ) ) { |
|
| 1271 | 1271 | $value = $entry[ $field->id ]; |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | // If this is a single upload file |
| 1275 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1276 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1277 | - $value = $file_path['url']; |
|
| 1275 | + if ( ! empty( $_FILES[ $input_name ] ) && ! empty( $_FILES[ $input_name ][ 'name' ] ) ) { |
|
| 1276 | + $file_path = GFFormsModel::get_file_upload_path( $form[ 'id' ], $_FILES[ $input_name ][ 'name' ] ); |
|
| 1277 | + $value = $file_path[ 'url' ]; |
|
| 1278 | 1278 | |
| 1279 | 1279 | } else { |
| 1280 | 1280 | |
| 1281 | 1281 | // Fix PHP warning on line 1498 of form_display.php for post_image fields |
| 1282 | 1282 | // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
| 1283 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1283 | + $_FILES[ $input_name ] = array( 'name' => '', 'size' => '' ); |
|
| 1284 | 1284 | |
| 1285 | 1285 | } |
| 1286 | 1286 | |
| 1287 | - if( rgar($field, "multipleFiles") ) { |
|
| 1287 | + if ( rgar( $field, "multipleFiles" ) ) { |
|
| 1288 | 1288 | |
| 1289 | 1289 | // If there are fresh uploads, process and merge them. |
| 1290 | 1290 | // Otherwise, use the passed values, which should be json-encoded array of URLs |
| 1291 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1291 | + if ( isset( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ) { |
|
| 1292 | 1292 | $value = empty( $value ) ? '[]' : $value; |
| 1293 | 1293 | $value = stripslashes_deep( $value ); |
| 1294 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1294 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ], array() ); |
|
| 1295 | 1295 | } |
| 1296 | 1296 | |
| 1297 | 1297 | } else { |
@@ -1309,14 +1309,14 @@ discard block |
||
| 1309 | 1309 | |
| 1310 | 1310 | case 'number': |
| 1311 | 1311 | // Fix "undefined index" issue at line 1286 in form_display.php |
| 1312 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1313 | - $_POST['input_'.$field->id ] = NULL; |
|
| 1312 | + if ( ! isset( $_POST[ 'input_' . $field->id ] ) ) { |
|
| 1313 | + $_POST[ 'input_' . $field->id ] = NULL; |
|
| 1314 | 1314 | } |
| 1315 | 1315 | break; |
| 1316 | 1316 | case 'captcha': |
| 1317 | 1317 | // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
| 1318 | - $_POST['recaptcha_challenge_field'] = NULL; |
|
| 1319 | - $_POST['recaptcha_response_field'] = NULL; |
|
| 1318 | + $_POST[ 'recaptcha_challenge_field' ] = NULL; |
|
| 1319 | + $_POST[ 'recaptcha_response_field' ] = NULL; |
|
| 1320 | 1320 | break; |
| 1321 | 1321 | } |
| 1322 | 1322 | |
@@ -1352,7 +1352,7 @@ discard block |
||
| 1352 | 1352 | * You can enter whatever you want! |
| 1353 | 1353 | * We try validating, and customize the results using `self::custom_validation()` |
| 1354 | 1354 | */ |
| 1355 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 1355 | + add_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10, 4 ); |
|
| 1356 | 1356 | |
| 1357 | 1357 | // Needed by the validate funtion |
| 1358 | 1358 | $failed_validation_page = NULL; |
@@ -1360,14 +1360,14 @@ discard block |
||
| 1360 | 1360 | |
| 1361 | 1361 | // Prevent entry limit from running when editing an entry, also |
| 1362 | 1362 | // prevent form scheduling from preventing editing |
| 1363 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 1363 | + unset( $this->form[ 'limitEntries' ], $this->form[ 'scheduleForm' ] ); |
|
| 1364 | 1364 | |
| 1365 | 1365 | // Hide fields depending on Edit Entry settings |
| 1366 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1366 | + $this->form[ 'fields' ] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1367 | 1367 | |
| 1368 | 1368 | $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
| 1369 | 1369 | |
| 1370 | - remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1370 | + remove_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | |
@@ -1384,13 +1384,13 @@ discard block |
||
| 1384 | 1384 | */ |
| 1385 | 1385 | public function custom_validation( $validation_results ) { |
| 1386 | 1386 | |
| 1387 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1387 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1388 | 1388 | |
| 1389 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1389 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1390 | 1390 | |
| 1391 | 1391 | $gv_valid = true; |
| 1392 | 1392 | |
| 1393 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1393 | + foreach ( $validation_results[ 'form' ][ 'fields' ] as $key => &$field ) { |
|
| 1394 | 1394 | |
| 1395 | 1395 | $value = RGFormsModel::get_field_value( $field ); |
| 1396 | 1396 | $field_type = RGFormsModel::get_input_type( $field ); |
@@ -1403,35 +1403,35 @@ discard block |
||
| 1403 | 1403 | case 'post_image': |
| 1404 | 1404 | |
| 1405 | 1405 | // in case nothing is uploaded but there are already files saved |
| 1406 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1406 | + if ( ! empty( $field->failed_validation ) && ! empty( $field->isRequired ) && ! empty( $value ) ) { |
|
| 1407 | 1407 | $field->failed_validation = false; |
| 1408 | 1408 | unset( $field->validation_message ); |
| 1409 | 1409 | } |
| 1410 | 1410 | |
| 1411 | 1411 | // validate if multi file upload reached max number of files [maxFiles] => 2 |
| 1412 | - if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1412 | + if ( rgobj( $field, 'maxFiles' ) && rgobj( $field, 'multipleFiles' ) ) { |
|
| 1413 | 1413 | |
| 1414 | 1414 | $input_name = 'input_' . $field->id; |
| 1415 | 1415 | //uploaded |
| 1416 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1416 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] : array(); |
|
| 1417 | 1417 | |
| 1418 | 1418 | //existent |
| 1419 | 1419 | $entry = $this->get_entry(); |
| 1420 | 1420 | $value = NULL; |
| 1421 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1421 | + if ( isset( $entry[ $field->id ] ) ) { |
|
| 1422 | 1422 | $value = json_decode( $entry[ $field->id ], true ); |
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | // count uploaded files and existent entry files |
| 1426 | 1426 | $count_files = count( $file_names ) + count( $value ); |
| 1427 | 1427 | |
| 1428 | - if( $count_files > $field->maxFiles ) { |
|
| 1428 | + if ( $count_files > $field->maxFiles ) { |
|
| 1429 | 1429 | $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
| 1430 | 1430 | $field->failed_validation = 1; |
| 1431 | 1431 | $gv_valid = false; |
| 1432 | 1432 | |
| 1433 | 1433 | // in case of error make sure the newest upload files are removed from the upload input |
| 1434 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1434 | + GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ] = null; |
|
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | } |
@@ -1442,7 +1442,7 @@ discard block |
||
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | // This field has failed validation. |
| 1445 | - if( !empty( $field->failed_validation ) ) { |
|
| 1445 | + if ( ! empty( $field->failed_validation ) ) { |
|
| 1446 | 1446 | |
| 1447 | 1447 | do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
| 1448 | 1448 | |
@@ -1460,32 +1460,32 @@ discard block |
||
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | // You can't continue inside a switch, so we do it after. |
| 1463 | - if( empty( $field->failed_validation ) ) { |
|
| 1463 | + if ( empty( $field->failed_validation ) ) { |
|
| 1464 | 1464 | continue; |
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | // checks if the No Duplicates option is not validating entry against itself, since |
| 1468 | 1468 | // we're editing a stored entry, it would also assume it's a duplicate. |
| 1469 | - if( !empty( $field->noDuplicates ) ) { |
|
| 1469 | + if ( ! empty( $field->noDuplicates ) ) { |
|
| 1470 | 1470 | |
| 1471 | 1471 | $entry = $this->get_entry(); |
| 1472 | 1472 | |
| 1473 | 1473 | // If the value of the entry is the same as the stored value |
| 1474 | 1474 | // Then we can assume it's not a duplicate, it's the same. |
| 1475 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1475 | + if ( ! empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1476 | 1476 | //if value submitted was not changed, then don't validate |
| 1477 | 1477 | $field->failed_validation = false; |
| 1478 | 1478 | |
| 1479 | 1479 | unset( $field->validation_message ); |
| 1480 | 1480 | |
| 1481 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1481 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1482 | 1482 | |
| 1483 | 1483 | continue; |
| 1484 | 1484 | } |
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | // if here then probably we are facing the validation 'At least one field must be filled out' |
| 1488 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1488 | + if ( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1489 | 1489 | unset( $field->validation_message ); |
| 1490 | 1490 | $field->validation_message = false; |
| 1491 | 1491 | continue; |
@@ -1497,12 +1497,12 @@ discard block |
||
| 1497 | 1497 | |
| 1498 | 1498 | } |
| 1499 | 1499 | |
| 1500 | - $validation_results['is_valid'] = $gv_valid; |
|
| 1500 | + $validation_results[ 'is_valid' ] = $gv_valid; |
|
| 1501 | 1501 | |
| 1502 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1502 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1503 | 1503 | |
| 1504 | 1504 | // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
| 1505 | - $this->form_after_validation = $validation_results['form']; |
|
| 1505 | + $this->form_after_validation = $validation_results[ 'form' ]; |
|
| 1506 | 1506 | |
| 1507 | 1507 | return $validation_results; |
| 1508 | 1508 | } |
@@ -1515,7 +1515,7 @@ discard block |
||
| 1515 | 1515 | */ |
| 1516 | 1516 | public function get_entry() { |
| 1517 | 1517 | |
| 1518 | - if( empty( $this->entry ) ) { |
|
| 1518 | + if ( empty( $this->entry ) ) { |
|
| 1519 | 1519 | // Get the database value of the entry that's being edited |
| 1520 | 1520 | $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
| 1521 | 1521 | } |
@@ -1542,13 +1542,13 @@ discard block |
||
| 1542 | 1542 | $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
| 1543 | 1543 | |
| 1544 | 1544 | // If edit tab not yet configured, show all fields |
| 1545 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1545 | + $edit_fields = ! empty( $properties[ 'edit_edit-fields' ] ) ? $properties[ 'edit_edit-fields' ] : NULL; |
|
| 1546 | 1546 | |
| 1547 | 1547 | // Show hidden fields as text fields |
| 1548 | 1548 | $form = $this->fix_survey_fields( $form ); |
| 1549 | 1549 | |
| 1550 | 1550 | // Hide fields depending on admin settings |
| 1551 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1551 | + $fields = $this->filter_fields( $form[ 'fields' ], $edit_fields ); |
|
| 1552 | 1552 | |
| 1553 | 1553 | // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
| 1554 | 1554 | $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
@@ -1578,7 +1578,7 @@ discard block |
||
| 1578 | 1578 | private function fix_survey_fields( $form ) { |
| 1579 | 1579 | |
| 1580 | 1580 | /** @var GF_Field $field */ |
| 1581 | - foreach( $form['fields'] as &$field ) { |
|
| 1581 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 1582 | 1582 | $field->allowsPrepopulate = true; |
| 1583 | 1583 | } |
| 1584 | 1584 | |
@@ -1599,7 +1599,7 @@ discard block |
||
| 1599 | 1599 | */ |
| 1600 | 1600 | private function filter_fields( $fields, $configured_fields ) { |
| 1601 | 1601 | |
| 1602 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1602 | + if ( empty( $fields ) || ! is_array( $fields ) ) { |
|
| 1603 | 1603 | return $fields; |
| 1604 | 1604 | } |
| 1605 | 1605 | |
@@ -1616,13 +1616,13 @@ discard block |
||
| 1616 | 1616 | */ |
| 1617 | 1617 | $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
| 1618 | 1618 | |
| 1619 | - if( $hide_product_fields ) { |
|
| 1620 | - $field_type_blacklist[] = 'option'; |
|
| 1621 | - $field_type_blacklist[] = 'quantity'; |
|
| 1622 | - $field_type_blacklist[] = 'product'; |
|
| 1623 | - $field_type_blacklist[] = 'total'; |
|
| 1624 | - $field_type_blacklist[] = 'shipping'; |
|
| 1625 | - $field_type_blacklist[] = 'calculation'; |
|
| 1619 | + if ( $hide_product_fields ) { |
|
| 1620 | + $field_type_blacklist[ ] = 'option'; |
|
| 1621 | + $field_type_blacklist[ ] = 'quantity'; |
|
| 1622 | + $field_type_blacklist[ ] = 'product'; |
|
| 1623 | + $field_type_blacklist[ ] = 'total'; |
|
| 1624 | + $field_type_blacklist[ ] = 'shipping'; |
|
| 1625 | + $field_type_blacklist[ ] = 'calculation'; |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | // First, remove blacklist or calculation fields |
@@ -1630,24 +1630,24 @@ discard block |
||
| 1630 | 1630 | |
| 1631 | 1631 | // Remove the fields that have calculation properties and keep them to be used later |
| 1632 | 1632 | // @since 1.16.2 |
| 1633 | - if( $field->has_calculation() ) { |
|
| 1634 | - $this->fields_with_calculation[] = $field; |
|
| 1633 | + if ( $field->has_calculation() ) { |
|
| 1634 | + $this->fields_with_calculation[ ] = $field; |
|
| 1635 | 1635 | // don't remove the calculation fields on form render. |
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | 1638 | // process total field after all fields have been saved |
| 1639 | 1639 | if ( $field->type == 'total' ) { |
| 1640 | - $this->total_fields[] = $field; |
|
| 1640 | + $this->total_fields[ ] = $field; |
|
| 1641 | 1641 | unset( $fields[ $key ] ); |
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1644 | + if ( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1645 | 1645 | unset( $fields[ $key ] ); |
| 1646 | 1646 | } |
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | 1649 | // The Edit tab has not been configured, so we return all fields by default. |
| 1650 | - if( empty( $configured_fields ) ) { |
|
| 1650 | + if ( empty( $configured_fields ) ) { |
|
| 1651 | 1651 | return $fields; |
| 1652 | 1652 | } |
| 1653 | 1653 | |
@@ -1657,8 +1657,8 @@ discard block |
||
| 1657 | 1657 | /** @var GF_Field $field */ |
| 1658 | 1658 | foreach ( $fields as $field ) { |
| 1659 | 1659 | |
| 1660 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1661 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1660 | + if ( intval( $configured_field[ 'id' ] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1661 | + $edit_fields[ ] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1662 | 1662 | break; |
| 1663 | 1663 | } |
| 1664 | 1664 | |
@@ -1681,14 +1681,14 @@ discard block |
||
| 1681 | 1681 | |
| 1682 | 1682 | $return_field = $field; |
| 1683 | 1683 | |
| 1684 | - if( empty( $field_setting['show_label'] ) ) { |
|
| 1684 | + if ( empty( $field_setting[ 'show_label' ] ) ) { |
|
| 1685 | 1685 | $return_field->label = ''; |
| 1686 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1687 | - $return_field->label = $field_setting['custom_label']; |
|
| 1686 | + } elseif ( ! empty( $field_setting[ 'custom_label' ] ) ) { |
|
| 1687 | + $return_field->label = $field_setting[ 'custom_label' ]; |
|
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1691 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1690 | + if ( ! empty( $field_setting[ 'custom_class' ] ) ) { |
|
| 1691 | + $return_field->cssClass .= ' ' . gravityview_sanitize_html_class( $field_setting[ 'custom_class' ] ); |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | /** |
@@ -1726,16 +1726,16 @@ discard block |
||
| 1726 | 1726 | */ |
| 1727 | 1727 | $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
| 1728 | 1728 | |
| 1729 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1730 | - foreach( $fields as $k => $field ) { |
|
| 1731 | - if( $field->adminOnly ) { |
|
| 1729 | + if ( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry[ 'id' ] ) ) { |
|
| 1730 | + foreach ( $fields as $k => $field ) { |
|
| 1731 | + if ( $field->adminOnly ) { |
|
| 1732 | 1732 | unset( $fields[ $k ] ); |
| 1733 | 1733 | } |
| 1734 | 1734 | } |
| 1735 | 1735 | return $fields; |
| 1736 | 1736 | } |
| 1737 | 1737 | |
| 1738 | - foreach( $fields as &$field ) { |
|
| 1738 | + foreach ( $fields as &$field ) { |
|
| 1739 | 1739 | $field->adminOnly = false; |
| 1740 | 1740 | } |
| 1741 | 1741 | |
@@ -1759,22 +1759,22 @@ discard block |
||
| 1759 | 1759 | */ |
| 1760 | 1760 | function prefill_conditional_logic( $form ) { |
| 1761 | 1761 | |
| 1762 | - if( ! GFFormDisplay::has_conditional_logic( $form ) ) { |
|
| 1762 | + if ( ! GFFormDisplay::has_conditional_logic( $form ) ) { |
|
| 1763 | 1763 | return $form; |
| 1764 | 1764 | } |
| 1765 | 1765 | |
| 1766 | 1766 | // Have Conditional Logic pre-fill fields as if the data were default values |
| 1767 | 1767 | /** @var GF_Field $field */ |
| 1768 | - foreach ( $form['fields'] as &$field ) { |
|
| 1768 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 1769 | 1769 | |
| 1770 | - if( 'checkbox' === $field->type ) { |
|
| 1770 | + if ( 'checkbox' === $field->type ) { |
|
| 1771 | 1771 | foreach ( $field->get_entry_inputs() as $key => $input ) { |
| 1772 | - $input_id = $input['id']; |
|
| 1772 | + $input_id = $input[ 'id' ]; |
|
| 1773 | 1773 | $choice = $field->choices[ $key ]; |
| 1774 | 1774 | $value = rgar( $this->entry, $input_id ); |
| 1775 | 1775 | $match = RGFormsModel::choice_value_match( $field, $choice, $value ); |
| 1776 | - if( $match ) { |
|
| 1777 | - $field->choices[ $key ]['isSelected'] = true; |
|
| 1776 | + if ( $match ) { |
|
| 1777 | + $field->choices[ $key ][ 'isSelected' ] = true; |
|
| 1778 | 1778 | } |
| 1779 | 1779 | } |
| 1780 | 1780 | } else { |
@@ -1782,15 +1782,15 @@ discard block |
||
| 1782 | 1782 | // We need to run through each field to set the default values |
| 1783 | 1783 | foreach ( $this->entry as $field_id => $field_value ) { |
| 1784 | 1784 | |
| 1785 | - if( floatval( $field_id ) === floatval( $field->id ) ) { |
|
| 1785 | + if ( floatval( $field_id ) === floatval( $field->id ) ) { |
|
| 1786 | 1786 | |
| 1787 | - if( 'list' === $field->type ) { |
|
| 1787 | + if ( 'list' === $field->type ) { |
|
| 1788 | 1788 | $list_rows = maybe_unserialize( $field_value ); |
| 1789 | 1789 | |
| 1790 | 1790 | $list_field_value = array(); |
| 1791 | 1791 | foreach ( $list_rows as $row ) { |
| 1792 | 1792 | foreach ( $row as $column ) { |
| 1793 | - $list_field_value[] = $column; |
|
| 1793 | + $list_field_value[ ] = $column; |
|
| 1794 | 1794 | } |
| 1795 | 1795 | } |
| 1796 | 1796 | |
@@ -1825,16 +1825,16 @@ discard block |
||
| 1825 | 1825 | */ |
| 1826 | 1826 | $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
| 1827 | 1827 | |
| 1828 | - if( $use_conditional_logic ) { |
|
| 1828 | + if ( $use_conditional_logic ) { |
|
| 1829 | 1829 | return $form; |
| 1830 | 1830 | } |
| 1831 | 1831 | |
| 1832 | - foreach( $form['fields'] as &$field ) { |
|
| 1832 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 1833 | 1833 | /* @var GF_Field $field */ |
| 1834 | 1834 | $field->conditionalLogic = null; |
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | - unset( $form['button']['conditionalLogic'] ); |
|
| 1837 | + unset( $form[ 'button' ][ 'conditionalLogic' ] ); |
|
| 1838 | 1838 | |
| 1839 | 1839 | return $form; |
| 1840 | 1840 | |
@@ -1851,7 +1851,7 @@ discard block |
||
| 1851 | 1851 | */ |
| 1852 | 1852 | public function manage_conditional_logic( $has_conditional_logic, $form ) { |
| 1853 | 1853 | |
| 1854 | - if( ! $this->is_edit_entry() ) { |
|
| 1854 | + if ( ! $this->is_edit_entry() ) { |
|
| 1855 | 1855 | return $has_conditional_logic; |
| 1856 | 1856 | } |
| 1857 | 1857 | |
@@ -1883,44 +1883,44 @@ discard block |
||
| 1883 | 1883 | * 2. There are two entries embedded using oEmbed |
| 1884 | 1884 | * 3. One of the entries has just been saved |
| 1885 | 1885 | */ |
| 1886 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1886 | + if ( ! empty( $_POST[ 'lid' ] ) && ! empty( $_GET[ 'entry' ] ) && ( $_POST[ 'lid' ] !== $_GET[ 'entry' ] ) ) { |
|
| 1887 | 1887 | |
| 1888 | 1888 | $error = true; |
| 1889 | 1889 | |
| 1890 | 1890 | } |
| 1891 | 1891 | |
| 1892 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1892 | + if ( ! empty( $_GET[ 'entry' ] ) && (string)$this->entry[ 'id' ] !== $_GET[ 'entry' ] ) { |
|
| 1893 | 1893 | |
| 1894 | 1894 | $error = true; |
| 1895 | 1895 | |
| 1896 | - } elseif( ! $this->verify_nonce() ) { |
|
| 1896 | + } elseif ( ! $this->verify_nonce() ) { |
|
| 1897 | 1897 | |
| 1898 | 1898 | /** |
| 1899 | 1899 | * If the Entry is embedded, there may be two entries on the same page. |
| 1900 | 1900 | * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
| 1901 | 1901 | */ |
| 1902 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1902 | + if ( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1903 | 1903 | $error = true; |
| 1904 | 1904 | } else { |
| 1905 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1905 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview' ); |
|
| 1906 | 1906 | } |
| 1907 | 1907 | |
| 1908 | 1908 | } |
| 1909 | 1909 | |
| 1910 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1911 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1910 | + if ( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1911 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview' ); |
|
| 1912 | 1912 | } |
| 1913 | 1913 | |
| 1914 | - if( $this->entry['status'] === 'trash' ) { |
|
| 1915 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1914 | + if ( $this->entry[ 'status' ] === 'trash' ) { |
|
| 1915 | + $error = __( 'You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1916 | 1916 | } |
| 1917 | 1917 | |
| 1918 | 1918 | // No errors; everything's fine here! |
| 1919 | - if( empty( $error ) ) { |
|
| 1919 | + if ( empty( $error ) ) { |
|
| 1920 | 1920 | return true; |
| 1921 | 1921 | } |
| 1922 | 1922 | |
| 1923 | - if( $echo && $error !== true ) { |
|
| 1923 | + if ( $echo && $error !== true ) { |
|
| 1924 | 1924 | |
| 1925 | 1925 | $error = esc_html( $error ); |
| 1926 | 1926 | |
@@ -1928,13 +1928,13 @@ discard block |
||
| 1928 | 1928 | * @since 1.9 |
| 1929 | 1929 | */ |
| 1930 | 1930 | if ( ! empty( $this->entry ) ) { |
| 1931 | - $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;" ) ); |
|
| 1931 | + $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;" ) ); |
|
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1934 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error' ); |
|
| 1935 | 1935 | } |
| 1936 | 1936 | |
| 1937 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1937 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1938 | 1938 | |
| 1939 | 1939 | return false; |
| 1940 | 1940 | } |
@@ -1951,20 +1951,20 @@ discard block |
||
| 1951 | 1951 | |
| 1952 | 1952 | $error = NULL; |
| 1953 | 1953 | |
| 1954 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1955 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1954 | + if ( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1955 | + $error = __( 'You do not have permission to edit this field.', 'gravityview' ); |
|
| 1956 | 1956 | } |
| 1957 | 1957 | |
| 1958 | 1958 | // No errors; everything's fine here! |
| 1959 | - if( empty( $error ) ) { |
|
| 1959 | + if ( empty( $error ) ) { |
|
| 1960 | 1960 | return true; |
| 1961 | 1961 | } |
| 1962 | 1962 | |
| 1963 | - if( $echo ) { |
|
| 1964 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1963 | + if ( $echo ) { |
|
| 1964 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error' ); |
|
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1967 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1968 | 1968 | |
| 1969 | 1969 | return false; |
| 1970 | 1970 | |
@@ -1982,15 +1982,15 @@ discard block |
||
| 1982 | 1982 | private function check_user_cap_edit_field( $field ) { |
| 1983 | 1983 | |
| 1984 | 1984 | // If they can edit any entries (as defined in Gravity Forms), we're good. |
| 1985 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1985 | + if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1986 | 1986 | return true; |
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1989 | + $field_cap = isset( $field[ 'allow_edit_cap' ] ) ? $field[ 'allow_edit_cap' ] : false; |
|
| 1990 | 1990 | |
| 1991 | 1991 | // If the field has custom editing capaibilities set, check those |
| 1992 | - if( $field_cap ) { |
|
| 1993 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1992 | + if ( $field_cap ) { |
|
| 1993 | + return GVCommon::has_cap( $field[ 'allow_edit_cap' ] ); |
|
| 1994 | 1994 | } |
| 1995 | 1995 | |
| 1996 | 1996 | return false; |
@@ -2004,17 +2004,17 @@ discard block |
||
| 2004 | 2004 | public function verify_nonce() { |
| 2005 | 2005 | |
| 2006 | 2006 | // Verify form submitted for editing single |
| 2007 | - if( $this->is_edit_entry_submission() ) { |
|
| 2007 | + if ( $this->is_edit_entry_submission() ) { |
|
| 2008 | 2008 | $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
| 2009 | 2009 | } |
| 2010 | 2010 | |
| 2011 | 2011 | // Verify |
| 2012 | - else if( ! $this->is_edit_entry() ) { |
|
| 2012 | + else if ( ! $this->is_edit_entry() ) { |
|
| 2013 | 2013 | $valid = false; |
| 2014 | 2014 | } |
| 2015 | 2015 | |
| 2016 | 2016 | else { |
| 2017 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 2017 | + $valid = wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ); |
|
| 2018 | 2018 | } |
| 2019 | 2019 | |
| 2020 | 2020 | /** |
@@ -59,8 +59,8 @@ |
||
| 59 | 59 | |
| 60 | 60 | $notes_table = class_exists( 'GFFormsModel' ) ? GFFormsModel::get_lead_notes_table_name() : $wpdb->prefix . 'rg_lead_notes'; |
| 61 | 61 | |
| 62 | - $disapproved = __('Disapproved the Entry for GravityView', 'gravityview'); |
|
| 63 | - $approved = __('Approved the Entry for GravityView', 'gravityview'); |
|
| 62 | + $disapproved = __( 'Disapproved the Entry for GravityView', 'gravityview' ); |
|
| 63 | + $approved = __( 'Approved the Entry for GravityView', 'gravityview' ); |
|
| 64 | 64 | |
| 65 | 65 | $sql = $wpdb->prepare( " |
| 66 | 66 | DELETE FROM $notes_table |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if( ! class_exists('GFAddOn') ) { |
|
| 3 | +if ( ! class_exists( 'GFAddOn' ) ) { |
|
| 4 | 4 | return; |
| 5 | 5 | } |
| 6 | 6 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function __construct( $prevent_multiple_instances = '' ) { |
| 77 | 77 | |
| 78 | - if( $prevent_multiple_instances === 'get_instance' ) { |
|
| 78 | + if ( $prevent_multiple_instances === 'get_instance' ) { |
|
| 79 | 79 | return parent::__construct(); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public static function get_instance() { |
| 89 | 89 | |
| 90 | - if( empty( self::$instance ) ) { |
|
| 90 | + if ( empty( self::$instance ) ) { |
|
| 91 | 91 | self::$instance = new self( 'get_instance' ); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function current_user_can_any( $caps ) { |
| 108 | 108 | |
| 109 | - if( empty( $caps ) ) { |
|
| 109 | + if ( empty( $caps ) ) { |
|
| 110 | 110 | $caps = array( 'gravityview_full_access' ); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | ), |
| 161 | 161 | 'found-other' => array( |
| 162 | 162 | 'label' => esc_html__( 'I found a better plugin', 'gravityview' ), |
| 163 | - 'followup' => esc_attr__('What plugin you are using, and why?', 'gravityview'), |
|
| 163 | + 'followup' => esc_attr__( 'What plugin you are using, and why?', 'gravityview' ), |
|
| 164 | 164 | ), |
| 165 | 165 | 'other' => array( |
| 166 | 166 | 'label' => esc_html__( 'Other', 'gravityview' ), |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | }); |
| 248 | 248 | |
| 249 | 249 | function gv_feedback_append_error_message() { |
| 250 | - $('#gv-uninstall-thanks').append('<div class="notice error"><?php echo esc_js( __('There was an error sharing your feedback. Sorry! Please email us at [email protected]', 'gravityview' ) ) ?></div>'); |
|
| 250 | + $('#gv-uninstall-thanks').append('<div class="notice error"><?php echo esc_js( __( 'There was an error sharing your feedback. Sorry! Please email us at [email protected]', 'gravityview' ) ) ?></div>'); |
|
| 251 | 251 | } |
| 252 | 252 | }); |
| 253 | 253 | </script> |
@@ -264,15 +264,15 @@ discard block |
||
| 264 | 264 | </ul> |
| 265 | 265 | <div class="gv-followup widefat"> |
| 266 | 266 | <p><strong><label for="gv-reason-details"><?php esc_html_e( 'Comments', 'gravityview' ); ?></label></strong></p> |
| 267 | - <textarea id="gv-reason-details" name="reason_details" data-default="<?php esc_attr_e('Please share your thoughts about GravityView', 'gravityview') ?>" placeholder="<?php esc_attr_e('Please share your thoughts about GravityView', 'gravityview'); ?>" class="large-text"></textarea> |
|
| 267 | + <textarea id="gv-reason-details" name="reason_details" data-default="<?php esc_attr_e( 'Please share your thoughts about GravityView', 'gravityview' ) ?>" placeholder="<?php esc_attr_e( 'Please share your thoughts about GravityView', 'gravityview' ); ?>" class="large-text"></textarea> |
|
| 268 | 268 | </div> |
| 269 | 269 | <div class="scale-description"> |
| 270 | - <p><strong><?php esc_html_e('How likely are you to recommend GravityView?', 'gravityview' ); ?></strong></p> |
|
| 270 | + <p><strong><?php esc_html_e( 'How likely are you to recommend GravityView?', 'gravityview' ); ?></strong></p> |
|
| 271 | 271 | <ul class="inline"> |
| 272 | 272 | <?php |
| 273 | 273 | $i = 0; |
| 274 | - while( $i < 11 ) { |
|
| 275 | - echo '<li class="inline number-scale"><label><input name="likely_to_refer" id="likely_to_refer_'.$i.'" value="'.$i.'" type="radio"> '.$i.'</label></li>'; |
|
| 274 | + while ( $i < 11 ) { |
|
| 275 | + echo '<li class="inline number-scale"><label><input name="likely_to_refer" id="likely_to_refer_' . $i . '" value="' . $i . '" type="radio"> ' . $i . '</label></li>'; |
|
| 276 | 276 | $i++; |
| 277 | 277 | } |
| 278 | 278 | ?> |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | </div> |
| 282 | 282 | |
| 283 | 283 | <div class="gv-form-field-wrapper"> |
| 284 | - <label><input type="checkbox" class="checkbox" name="follow_up_with_me" value="1" /> <?php esc_html_e('Please follow up with me about my feedback', 'gravityview'); ?></label> |
|
| 284 | + <label><input type="checkbox" class="checkbox" name="follow_up_with_me" value="1" /> <?php esc_html_e( 'Please follow up with me about my feedback', 'gravityview' ); ?></label> |
|
| 285 | 285 | </div> |
| 286 | 286 | |
| 287 | 287 | <div class="submit"> |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | <div id="gv-uninstall-thanks" class="notice notice-large notice-updated below-h2" style="display:none;"> |
| 296 | 296 | <h3 class="notice-title"><?php esc_html_e( 'Thank you for using GravityView!', 'gravityview' ); ?></h3> |
| 297 | 297 | <p><?php echo gravityview_get_floaty(); ?> |
| 298 | - <?php echo make_clickable( esc_html__('Your feedback helps us improve GravityView. If you have any questions or comments, email us: [email protected]', 'gravityview' ) ); ?> |
|
| 298 | + <?php echo make_clickable( esc_html__( 'Your feedback helps us improve GravityView. If you have any questions or comments, email us: [email protected]', 'gravityview' ) ); ?> |
|
| 299 | 299 | </p> |
| 300 | 300 | <div class="wp-clearfix"></div> |
| 301 | 301 | </div> |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | add_filter( 'gform_addon_app_settings_menu_gravityview', array( $this, 'modify_app_settings_menu_title' ) ); |
| 370 | 370 | |
| 371 | 371 | /** @since 1.7.6 */ |
| 372 | - add_action('network_admin_menu', array( $this, 'add_network_menu' ) ); |
|
| 372 | + add_action( 'network_admin_menu', array( $this, 'add_network_menu' ) ); |
|
| 373 | 373 | |
| 374 | 374 | parent::init_admin(); |
| 375 | 375 | } |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | */ |
| 384 | 384 | public function modify_app_settings_menu_title( $setting_tabs ) { |
| 385 | 385 | |
| 386 | - $setting_tabs[0]['label'] = __( 'GravityView Settings', 'gravityview'); |
|
| 386 | + $setting_tabs[ 0 ][ 'label' ] = __( 'GravityView Settings', 'gravityview' ); |
|
| 387 | 387 | |
| 388 | 388 | return $setting_tabs; |
| 389 | 389 | } |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | */ |
| 401 | 401 | private function _load_license_handler() { |
| 402 | 402 | |
| 403 | - if( !empty( $this->License_Handler ) ) { |
|
| 403 | + if ( ! empty( $this->License_Handler ) ) { |
|
| 404 | 404 | return; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php'); |
|
| 407 | + require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php' ); |
|
| 408 | 408 | |
| 409 | 409 | $this->License_Handler = GV_License_Handler::get_instance( $this ); |
| 410 | 410 | } |
@@ -416,42 +416,42 @@ discard block |
||
| 416 | 416 | function license_key_notice() { |
| 417 | 417 | |
| 418 | 418 | // Only show on GravityView pages |
| 419 | - if( ! gravityview_is_admin_page() ) { |
|
| 419 | + if ( ! gravityview_is_admin_page() ) { |
|
| 420 | 420 | return; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - $license_status = self::getSetting('license_key_status'); |
|
| 424 | - $license_key = self::getSetting('license_key'); |
|
| 425 | - if( '' === $license_key ) { |
|
| 423 | + $license_status = self::getSetting( 'license_key_status' ); |
|
| 424 | + $license_key = self::getSetting( 'license_key' ); |
|
| 425 | + if ( '' === $license_key ) { |
|
| 426 | 426 | $license_status = 'inactive'; |
| 427 | 427 | } |
| 428 | 428 | $license_id = empty( $license_key ) ? 'license' : $license_key; |
| 429 | 429 | |
| 430 | - $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'); |
|
| 430 | + $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' ); |
|
| 431 | 431 | |
| 432 | 432 | /** |
| 433 | 433 | * I wanted to remove the period from after the buttons in the string, |
| 434 | 434 | * but didn't want to mess up the translation strings for the translators. |
| 435 | 435 | */ |
| 436 | 436 | $message = mb_substr( $message, 0, mb_strlen( $message ) - 1 ); |
| 437 | - $title = __('Inactive License', 'gravityview'); |
|
| 437 | + $title = __( 'Inactive License', 'gravityview' ); |
|
| 438 | 438 | $status = ''; |
| 439 | 439 | $update_below = false; |
| 440 | 440 | $primary_button_link = admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ); |
| 441 | 441 | switch ( $license_status ) { |
| 442 | 442 | /** @since 1.17 */ |
| 443 | 443 | case 'expired': |
| 444 | - $title = __('Expired License', 'gravityview'); |
|
| 444 | + $title = __( 'Expired License', 'gravityview' ); |
|
| 445 | 445 | $status = 'expired'; |
| 446 | - $message = $this->get_license_handler()->strings( 'expired', self::getSetting('license_key_response') ); |
|
| 446 | + $message = $this->get_license_handler()->strings( 'expired', self::getSetting( 'license_key_response' ) ); |
|
| 447 | 447 | break; |
| 448 | 448 | case 'invalid': |
| 449 | - $title = __('Invalid License', 'gravityview'); |
|
| 450 | - $status = __('is invalid', 'gravityview'); |
|
| 449 | + $title = __( 'Invalid License', 'gravityview' ); |
|
| 450 | + $status = __( 'is invalid', 'gravityview' ); |
|
| 451 | 451 | break; |
| 452 | 452 | case 'deactivated': |
| 453 | - $status = __('is inactive', 'gravityview'); |
|
| 454 | - $update_below = __('Activate your license key below.', 'gravityview'); |
|
| 453 | + $status = __( 'is inactive', 'gravityview' ); |
|
| 454 | + $update_below = __( 'Activate your license key below.', 'gravityview' ); |
|
| 455 | 455 | break; |
| 456 | 456 | /** @noinspection PhpMissingBreakStatementInspection */ |
| 457 | 457 | case '': |
@@ -459,27 +459,27 @@ discard block |
||
| 459 | 459 | // break intentionally left blank |
| 460 | 460 | case 'inactive': |
| 461 | 461 | case 'site_inactive': |
| 462 | - $status = __('has not been activated', 'gravityview'); |
|
| 463 | - $update_below = __('Activate your license key below.', 'gravityview'); |
|
| 462 | + $status = __( 'has not been activated', 'gravityview' ); |
|
| 463 | + $update_below = __( 'Activate your license key below.', 'gravityview' ); |
|
| 464 | 464 | break; |
| 465 | 465 | } |
| 466 | - $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice'; |
|
| 466 | + $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content=' . $license_status . '&utm_campaign=Admin%20Notice'; |
|
| 467 | 467 | |
| 468 | 468 | // Show a different notice on settings page for inactive licenses (hide the buttons) |
| 469 | - if( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { |
|
| 469 | + if ( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { |
|
| 470 | 470 | $message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' ); |
| 471 | 471 | } else { |
| 472 | 472 | $message = sprintf( $message, $status, "\n\n" . '<a href="' . esc_url( $primary_button_link ) . '" class="button button-primary">', '</a>', '<a href="' . esc_url( $url ) . '" class="button button-secondary">', '</a>' ); |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - if( !empty( $status ) ) { |
|
| 475 | + if ( ! empty( $status ) ) { |
|
| 476 | 476 | GravityView_Admin_Notices::add_notice( array( |
| 477 | 477 | 'message' => $message, |
| 478 | 478 | 'class' => 'updated', |
| 479 | 479 | 'title' => $title, |
| 480 | 480 | 'cap' => 'gravityview_edit_settings', |
| 481 | - 'dismiss' => sha1( $license_status.'_'.$license_id ), |
|
| 482 | - )); |
|
| 481 | + 'dismiss' => sha1( $license_status . '_' . $license_id ), |
|
| 482 | + ) ); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | |
| 492 | 492 | $styles = parent::styles(); |
| 493 | 493 | |
| 494 | - $styles[] = array( |
|
| 494 | + $styles[ ] = array( |
|
| 495 | 495 | 'handle' => 'gravityview_settings', |
| 496 | 496 | 'src' => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ), |
| 497 | 497 | 'version' => GravityView_Plugin::version, |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | * @return void |
| 515 | 515 | */ |
| 516 | 516 | public function add_network_menu() { |
| 517 | - if( GravityView_Plugin::is_network_activated() ) { |
|
| 517 | + if ( GravityView_Plugin::is_network_activated() ) { |
|
| 518 | 518 | add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' ); |
| 519 | 519 | } |
| 520 | 520 | } |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | * If multisite and not network admin, we don't want the settings to show. |
| 532 | 532 | * @since 1.7.6 |
| 533 | 533 | */ |
| 534 | - $show_submenu = !is_multisite() || is_main_site() || !GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); |
|
| 534 | + $show_submenu = ! is_multisite() || is_main_site() || ! GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); |
|
| 535 | 535 | |
| 536 | 536 | /** |
| 537 | 537 | * Override whether to show the Settings menu on a per-blog basis. |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | */ |
| 541 | 541 | $show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu ); |
| 542 | 542 | |
| 543 | - if( $show_submenu ) { |
|
| 543 | + if ( $show_submenu ) { |
|
| 544 | 544 | add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) ); |
| 545 | 545 | } |
| 546 | 546 | } |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | /** |
| 580 | 580 | * Backward compatibility with Redux |
| 581 | 581 | */ |
| 582 | - if( $setting_name === 'license' ) { |
|
| 582 | + if ( $setting_name === 'license' ) { |
|
| 583 | 583 | return array( |
| 584 | 584 | 'license' => parent::get_app_setting( 'license_key' ), |
| 585 | 585 | 'status' => parent::get_app_setting( 'license_key_status' ), |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | |
| 644 | 644 | $return = $text . $activation; |
| 645 | 645 | |
| 646 | - if( $echo ) { |
|
| 646 | + if ( $echo ) { |
|
| 647 | 647 | echo $return; |
| 648 | 648 | } |
| 649 | 649 | |
@@ -670,15 +670,15 @@ discard block |
||
| 670 | 670 | */ |
| 671 | 671 | public function settings_submit( $field, $echo = true ) { |
| 672 | 672 | |
| 673 | - $field['type'] = ( isset($field['type']) && in_array( $field['type'], array('submit','reset','button') ) ) ? $field['type'] : 'submit'; |
|
| 673 | + $field[ 'type' ] = ( isset( $field[ 'type' ] ) && in_array( $field[ 'type' ], array( 'submit', 'reset', 'button' ) ) ) ? $field[ 'type' ] : 'submit'; |
|
| 674 | 674 | |
| 675 | 675 | $attributes = $this->get_field_attributes( $field ); |
| 676 | 676 | $default_value = rgar( $field, 'value' ) ? rgar( $field, 'value' ) : rgar( $field, 'default_value' ); |
| 677 | - $value = $this->get_setting( $field['name'], $default_value ); |
|
| 677 | + $value = $this->get_setting( $field[ 'name' ], $default_value ); |
|
| 678 | 678 | |
| 679 | 679 | |
| 680 | - $attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton'; |
|
| 681 | - $name = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_'.$field['name']; |
|
| 680 | + $attributes[ 'class' ] = isset( $attributes[ 'class' ] ) ? esc_attr( $attributes[ 'class' ] ) : 'button-primary gfbutton'; |
|
| 681 | + $name = ( $field[ 'name' ] === 'gform-settings-save' ) ? $field[ 'name' ] : '_gaddon_setting_' . $field[ 'name' ]; |
|
| 682 | 682 | |
| 683 | 683 | if ( empty( $value ) ) { |
| 684 | 684 | $value = __( 'Update Settings', 'gravityview' ); |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | $attributes = $this->get_field_attributes( $field ); |
| 688 | 688 | |
| 689 | 689 | $html = '<input |
| 690 | - type="' . $field['type'] . '" |
|
| 690 | + type="' . $field[ 'type' ] . '" |
|
| 691 | 691 | name="' . esc_attr( $name ) . '" |
| 692 | 692 | value="' . $value . '" ' . |
| 693 | 693 | implode( ' ', $attributes ) . |
@@ -709,12 +709,12 @@ discard block |
||
| 709 | 709 | * @return string |
| 710 | 710 | */ |
| 711 | 711 | public function settings_save( $field, $echo = true ) { |
| 712 | - $field['type'] = 'submit'; |
|
| 713 | - $field['name'] = 'gform-settings-save'; |
|
| 714 | - $field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton'; |
|
| 712 | + $field[ 'type' ] = 'submit'; |
|
| 713 | + $field[ 'name' ] = 'gform-settings-save'; |
|
| 714 | + $field[ 'class' ] = isset( $field[ 'class' ] ) ? $field[ 'class' ] : 'button-primary gfbutton'; |
|
| 715 | 715 | |
| 716 | 716 | if ( ! rgar( $field, 'value' ) ) { |
| 717 | - $field['value'] = __( 'Update Settings', 'gravityview' ); |
|
| 717 | + $field[ 'value' ] = __( 'Update Settings', 'gravityview' ); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | $output = $this->settings_submit( $field, false ); |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | $this->app_settings_uninstall_tab(); |
| 724 | 724 | $output .= ob_get_clean(); |
| 725 | 725 | |
| 726 | - if( $echo ) { |
|
| 726 | + if ( $echo ) { |
|
| 727 | 727 | echo $output; |
| 728 | 728 | } |
| 729 | 729 | |
@@ -741,8 +741,8 @@ discard block |
||
| 741 | 741 | parent::single_setting_label( $field ); |
| 742 | 742 | |
| 743 | 743 | // Added by GravityView |
| 744 | - if ( isset( $field['description'] ) ) { |
|
| 745 | - echo '<span class="description">'. $field['description'] .'</span>'; |
|
| 744 | + if ( isset( $field[ 'description' ] ) ) { |
|
| 745 | + echo '<span class="description">' . $field[ 'description' ] . '</span>'; |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | } |
@@ -804,11 +804,11 @@ discard block |
||
| 804 | 804 | |
| 805 | 805 | // If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response), |
| 806 | 806 | // then we assume it's changed. If it's changed, unset the status and the previous response. |
| 807 | - if( $local_key !== $response_key ) { |
|
| 807 | + if ( $local_key !== $response_key ) { |
|
| 808 | 808 | |
| 809 | - unset( $posted_settings['license_key_response'] ); |
|
| 810 | - unset( $posted_settings['license_key_status'] ); |
|
| 811 | - GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); |
|
| 809 | + unset( $posted_settings[ 'license_key_response' ] ); |
|
| 810 | + unset( $posted_settings[ 'license_key_status' ] ); |
|
| 811 | + GFCommon::add_error_message( __( 'The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | return $posted_settings; |
@@ -843,25 +843,25 @@ discard block |
||
| 843 | 843 | 'label' => __( 'License Key', 'gravityview' ), |
| 844 | 844 | 'description' => __( 'Enter the license key that was sent to you on purchase. This enables plugin updates & support.', 'gravityview' ) . $this->get_license_handler()->license_details( $this->get_app_setting( 'license_key_response' ) ), |
| 845 | 845 | 'type' => 'edd_license', |
| 846 | - 'data-pending-text' => __('Verifying license…', 'gravityview'), |
|
| 847 | - 'default_value' => $default_settings['license_key'], |
|
| 846 | + 'data-pending-text' => __( 'Verifying license…', 'gravityview' ), |
|
| 847 | + 'default_value' => $default_settings[ 'license_key' ], |
|
| 848 | 848 | 'class' => ( '' == $this->get_app_setting( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key', |
| 849 | 849 | ), |
| 850 | 850 | array( |
| 851 | 851 | 'name' => 'license_key_response', |
| 852 | - 'default_value' => $default_settings['license_key_response'], |
|
| 852 | + 'default_value' => $default_settings[ 'license_key_response' ], |
|
| 853 | 853 | 'type' => 'hidden', |
| 854 | 854 | ), |
| 855 | 855 | array( |
| 856 | 856 | 'name' => 'license_key_status', |
| 857 | - 'default_value' => $default_settings['license_key_status'], |
|
| 857 | + 'default_value' => $default_settings[ 'license_key_status' ], |
|
| 858 | 858 | 'type' => 'hidden', |
| 859 | 859 | ), |
| 860 | 860 | array( |
| 861 | 861 | 'name' => 'support-email', |
| 862 | 862 | 'type' => 'text', |
| 863 | 863 | 'validate' => 'email', |
| 864 | - 'default_value' => $default_settings['support-email'], |
|
| 864 | + 'default_value' => $default_settings[ 'support-email' ], |
|
| 865 | 865 | 'label' => __( 'Support Email', 'gravityview' ), |
| 866 | 866 | 'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ), |
| 867 | 867 | 'class' => 'code regular-text', |
@@ -873,38 +873,38 @@ discard block |
||
| 873 | 873 | 'name' => 'support_port', |
| 874 | 874 | 'type' => 'radio', |
| 875 | 875 | 'label' => __( 'Show Support Port?', 'gravityview' ), |
| 876 | - 'default_value' => $default_settings['support_port'], |
|
| 876 | + 'default_value' => $default_settings[ 'support_port' ], |
|
| 877 | 877 | 'horizontal' => 1, |
| 878 | 878 | 'choices' => array( |
| 879 | 879 | array( |
| 880 | - 'label' => _x('Show', 'Setting: Show or Hide', 'gravityview'), |
|
| 880 | + 'label' => _x( 'Show', 'Setting: Show or Hide', 'gravityview' ), |
|
| 881 | 881 | 'value' => '1', |
| 882 | 882 | ), |
| 883 | 883 | array( |
| 884 | - 'label' => _x('Hide', 'Setting: Show or Hide', 'gravityview'), |
|
| 884 | + 'label' => _x( 'Hide', 'Setting: Show or Hide', 'gravityview' ), |
|
| 885 | 885 | 'value' => '0', |
| 886 | 886 | ), |
| 887 | 887 | ), |
| 888 | - '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>', |
|
| 888 | + '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>', |
|
| 889 | 889 | 'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ), |
| 890 | 890 | ), |
| 891 | 891 | array( |
| 892 | 892 | 'name' => 'no-conflict-mode', |
| 893 | 893 | 'type' => 'radio', |
| 894 | 894 | 'label' => __( 'No-Conflict Mode', 'gravityview' ), |
| 895 | - 'default_value' => $default_settings['no-conflict-mode'], |
|
| 895 | + 'default_value' => $default_settings[ 'no-conflict-mode' ], |
|
| 896 | 896 | 'horizontal' => 1, |
| 897 | 897 | 'choices' => array( |
| 898 | 898 | array( |
| 899 | - 'label' => _x('On', 'Setting: On or off', 'gravityview'), |
|
| 899 | + 'label' => _x( 'On', 'Setting: On or off', 'gravityview' ), |
|
| 900 | 900 | 'value' => '1', |
| 901 | 901 | ), |
| 902 | 902 | array( |
| 903 | - 'label' => _x('Off', 'Setting: On or off', 'gravityview'), |
|
| 903 | + 'label' => _x( 'Off', 'Setting: On or off', 'gravityview' ), |
|
| 904 | 904 | 'value' => '0', |
| 905 | 905 | ), |
| 906 | 906 | ), |
| 907 | - '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'), |
|
| 907 | + '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' ), |
|
| 908 | 908 | ), |
| 909 | 909 | ) ); |
| 910 | 910 | |
@@ -915,20 +915,20 @@ discard block |
||
| 915 | 915 | * @since 1.7.4 |
| 916 | 916 | */ |
| 917 | 917 | foreach ( $fields as &$field ) { |
| 918 | - $field['name'] = isset( $field['name'] ) ? $field['name'] : rgget('id', $field ); |
|
| 919 | - $field['label'] = isset( $field['label'] ) ? $field['label'] : rgget('title', $field ); |
|
| 920 | - $field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : rgget('default', $field ); |
|
| 921 | - $field['description'] = isset( $field['description'] ) ? $field['description'] : rgget('subtitle', $field ); |
|
| 918 | + $field[ 'name' ] = isset( $field[ 'name' ] ) ? $field[ 'name' ] : rgget( 'id', $field ); |
|
| 919 | + $field[ 'label' ] = isset( $field[ 'label' ] ) ? $field[ 'label' ] : rgget( 'title', $field ); |
|
| 920 | + $field[ 'default_value' ] = isset( $field[ 'default_value' ] ) ? $field[ 'default_value' ] : rgget( 'default', $field ); |
|
| 921 | + $field[ 'description' ] = isset( $field[ 'description' ] ) ? $field[ 'description' ] : rgget( 'subtitle', $field ); |
|
| 922 | 922 | |
| 923 | - if( $disabled_attribute ) { |
|
| 924 | - $field['disabled'] = $disabled_attribute; |
|
| 923 | + if ( $disabled_attribute ) { |
|
| 924 | + $field[ 'disabled' ] = $disabled_attribute; |
|
| 925 | 925 | } |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | |
| 929 | 929 | $sections = array( |
| 930 | 930 | array( |
| 931 | - 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
| 931 | + 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __( 'You are running GravityView version %s', 'gravityview' ), GravityView_Plugin::version ) ), |
|
| 932 | 932 | 'fields' => $fields, |
| 933 | 933 | ) |
| 934 | 934 | ); |
@@ -939,8 +939,8 @@ discard block |
||
| 939 | 939 | 'type' => 'save', |
| 940 | 940 | ); |
| 941 | 941 | |
| 942 | - if( $disabled_attribute ) { |
|
| 943 | - $button['disabled'] = $disabled_attribute; |
|
| 942 | + if ( $disabled_attribute ) { |
|
| 943 | + $button[ 'disabled' ] = $disabled_attribute; |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | |
@@ -960,20 +960,20 @@ discard block |
||
| 960 | 960 | // If there are extensions, add a section for them |
| 961 | 961 | if ( ! empty( $extension_sections ) ) { |
| 962 | 962 | |
| 963 | - if( $disabled_attribute ) { |
|
| 963 | + if ( $disabled_attribute ) { |
|
| 964 | 964 | foreach ( $extension_sections as &$section ) { |
| 965 | - foreach ( $section['fields'] as &$field ) { |
|
| 966 | - $field['disabled'] = $disabled_attribute; |
|
| 965 | + foreach ( $section[ 'fields' ] as &$field ) { |
|
| 966 | + $field[ 'disabled' ] = $disabled_attribute; |
|
| 967 | 967 | } |
| 968 | 968 | } |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | - $k = count( $extension_sections ) - 1 ; |
|
| 972 | - $extension_sections[ $k ]['fields'][] = $button; |
|
| 971 | + $k = count( $extension_sections ) - 1; |
|
| 972 | + $extension_sections[ $k ][ 'fields' ][ ] = $button; |
|
| 973 | 973 | $sections = array_merge( $sections, $extension_sections ); |
| 974 | 974 | } else { |
| 975 | 975 | // add the 'update settings' button to the general section |
| 976 | - $sections[0]['fields'][] = $button; |
|
| 976 | + $sections[ 0 ][ 'fields' ][ ] = $button; |
|
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | return $sections; |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Uninstall all traces of GravityView |
|
| 126 | - * |
|
| 127 | - * Note: method is public because parent method is public |
|
| 128 | - * |
|
| 125 | + * Uninstall all traces of GravityView |
|
| 126 | + * |
|
| 127 | + * Note: method is public because parent method is public |
|
| 128 | + * |
|
| 129 | 129 | * @return bool |
| 130 | 130 | */ |
| 131 | 131 | public function uninstall() { |
@@ -137,53 +137,53 @@ discard block |
||
| 137 | 137 | $uninstaller->fire_everything(); |
| 138 | 138 | |
| 139 | 139 | /** |
| 140 | - * Set the path so that Gravity Forms can de-activate GravityView |
|
| 141 | - * @see GFAddOn::uninstall_addon |
|
| 142 | - * @uses deactivate_plugins() |
|
| 143 | - */ |
|
| 140 | + * Set the path so that Gravity Forms can de-activate GravityView |
|
| 141 | + * @see GFAddOn::uninstall_addon |
|
| 142 | + * @uses deactivate_plugins() |
|
| 143 | + */ |
|
| 144 | 144 | $this->_path = GRAVITYVIEW_FILE; |
| 145 | 145 | |
| 146 | 146 | return true; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | - * Get an array of reasons why the plugin might be uninstalled |
|
| 151 | - * |
|
| 152 | - * @since 1.17.5 |
|
| 153 | - * |
|
| 150 | + * Get an array of reasons why the plugin might be uninstalled |
|
| 151 | + * |
|
| 152 | + * @since 1.17.5 |
|
| 153 | + * |
|
| 154 | 154 | * @return array Array of reasons with the label and followup questions for each uninstall reason |
| 155 | 155 | */ |
| 156 | 156 | private function get_uninstall_reasons() { |
| 157 | 157 | |
| 158 | 158 | $reasons = array( |
| 159 | 159 | 'will-continue' => array( |
| 160 | - 'label' => esc_html__( 'I am going to continue using GravityView', 'gravityview' ), |
|
| 161 | - ), |
|
| 160 | + 'label' => esc_html__( 'I am going to continue using GravityView', 'gravityview' ), |
|
| 161 | + ), |
|
| 162 | 162 | 'no-longer-need' => array( |
| 163 | - 'label' => esc_html__( 'I no longer need GravityView', 'gravityview' ), |
|
| 164 | - ), |
|
| 163 | + 'label' => esc_html__( 'I no longer need GravityView', 'gravityview' ), |
|
| 164 | + ), |
|
| 165 | 165 | 'doesnt-work' => array( |
| 166 | - 'label' => esc_html__( 'The plugin doesn\'t work', 'gravityview' ), |
|
| 167 | - ), |
|
| 166 | + 'label' => esc_html__( 'The plugin doesn\'t work', 'gravityview' ), |
|
| 167 | + ), |
|
| 168 | 168 | 'found-other' => array( |
| 169 | - 'label' => esc_html__( 'I found a better plugin', 'gravityview' ), |
|
| 170 | - 'followup' => esc_attr__('What plugin you are using, and why?', 'gravityview'), |
|
| 171 | - ), |
|
| 169 | + 'label' => esc_html__( 'I found a better plugin', 'gravityview' ), |
|
| 170 | + 'followup' => esc_attr__('What plugin you are using, and why?', 'gravityview'), |
|
| 171 | + ), |
|
| 172 | 172 | 'other' => array( |
| 173 | - 'label' => esc_html__( 'Other', 'gravityview' ), |
|
| 174 | - ), |
|
| 173 | + 'label' => esc_html__( 'Other', 'gravityview' ), |
|
| 174 | + ), |
|
| 175 | 175 | ); |
| 176 | 176 | |
| 177 | 177 | shuffle( $reasons ); |
| 178 | 178 | |
| 179 | 179 | return $reasons; |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | - * Display a feedback form when the plugin is uninstalled |
|
| 184 | - * |
|
| 185 | - * @since 1.17.5 |
|
| 186 | - * |
|
| 183 | + * Display a feedback form when the plugin is uninstalled |
|
| 184 | + * |
|
| 185 | + * @since 1.17.5 |
|
| 186 | + * |
|
| 187 | 187 | * @return string HTML of the uninstallation form |
| 188 | 188 | */ |
| 189 | 189 | public function uninstall_form() { |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | <h2><?php esc_html_e( 'Why did you uninstall GravityView?', 'gravityview' ); ?></h2> |
| 264 | 264 | <ul> |
| 265 | 265 | <?php |
| 266 | - $reasons = $this->get_uninstall_reasons(); |
|
| 266 | + $reasons = $this->get_uninstall_reasons(); |
|
| 267 | 267 | foreach ( $reasons as $reason ) { |
| 268 | 268 | printf( '<li><label><input name="reason" type="radio" value="other" data-followup="%s"> %s</label></li>', rgar( $reason, 'followup' ), rgar( $reason, 'label' ) ); |
| 269 | 269 | } |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | $license_key = self::getSetting('license_key'); |
| 432 | 432 | if( '' === $license_key ) { |
| 433 | 433 | $license_status = 'inactive'; |
| 434 | - } |
|
| 434 | + } |
|
| 435 | 435 | $license_id = empty( $license_key ) ? 'license' : $license_key; |
| 436 | 436 | |
| 437 | 437 | $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'); |
@@ -569,12 +569,12 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | public function app_settings_tab() { |
| 572 | - parent::app_settings_tab(); |
|
| 572 | + parent::app_settings_tab(); |
|
| 573 | 573 | |
| 574 | 574 | if ( $this->maybe_uninstall() ) { |
| 575 | - echo $this->uninstall_form(); |
|
| 575 | + echo $this->uninstall_form(); |
|
| 576 | 576 | } |
| 577 | - } |
|
| 577 | + } |
|
| 578 | 578 | |
| 579 | 579 | /** |
| 580 | 580 | * Make protected public |
@@ -697,8 +697,8 @@ discard block |
||
| 697 | 697 | type="' . $field['type'] . '" |
| 698 | 698 | name="' . esc_attr( $name ) . '" |
| 699 | 699 | value="' . $value . '" ' . |
| 700 | - implode( ' ', $attributes ) . |
|
| 701 | - ' />'; |
|
| 700 | + implode( ' ', $attributes ) . |
|
| 701 | + ' />'; |
|
| 702 | 702 | |
| 703 | 703 | if ( $echo ) { |
| 704 | 704 | echo $html; |
@@ -933,36 +933,36 @@ discard block |
||
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | |
| 936 | - $sections = array( |
|
| 937 | - array( |
|
| 938 | - 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
| 939 | - 'fields' => $fields, |
|
| 940 | - ) |
|
| 941 | - ); |
|
| 936 | + $sections = array( |
|
| 937 | + array( |
|
| 938 | + 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
| 939 | + 'fields' => $fields, |
|
| 940 | + ) |
|
| 941 | + ); |
|
| 942 | 942 | |
| 943 | - // custom 'update settings' button |
|
| 944 | - $button = array( |
|
| 945 | - 'class' => 'button button-primary button-hero', |
|
| 946 | - 'type' => 'save', |
|
| 947 | - ); |
|
| 943 | + // custom 'update settings' button |
|
| 944 | + $button = array( |
|
| 945 | + 'class' => 'button button-primary button-hero', |
|
| 946 | + 'type' => 'save', |
|
| 947 | + ); |
|
| 948 | 948 | |
| 949 | 949 | if( $disabled_attribute ) { |
| 950 | 950 | $button['disabled'] = $disabled_attribute; |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | |
| 954 | - /** |
|
| 955 | - * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page |
|
| 956 | - * Extensions can tap in here to insert their own section and settings. |
|
| 957 | - * <code> |
|
| 958 | - * $sections[] = array( |
|
| 959 | - * 'title' => __( 'GravityView My Extension Settings', 'gravityview' ), |
|
| 960 | - * 'fields' => $settings, |
|
| 961 | - * ); |
|
| 962 | - * </code> |
|
| 963 | - * @param array $extension_settings Empty array, ready for extension settings! |
|
| 964 | - */ |
|
| 965 | - $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() ); |
|
| 954 | + /** |
|
| 955 | + * @filter `gravityview/settings/extension/sections` Modify the GravityView settings page |
|
| 956 | + * Extensions can tap in here to insert their own section and settings. |
|
| 957 | + * <code> |
|
| 958 | + * $sections[] = array( |
|
| 959 | + * 'title' => __( 'GravityView My Extension Settings', 'gravityview' ), |
|
| 960 | + * 'fields' => $settings, |
|
| 961 | + * ); |
|
| 962 | + * </code> |
|
| 963 | + * @param array $extension_settings Empty array, ready for extension settings! |
|
| 964 | + */ |
|
| 965 | + $extension_sections = apply_filters( 'gravityview/settings/extension/sections', array() ); |
|
| 966 | 966 | |
| 967 | 967 | // If there are extensions, add a section for them |
| 968 | 968 | if ( ! empty( $extension_sections ) ) { |
@@ -975,13 +975,13 @@ discard block |
||
| 975 | 975 | } |
| 976 | 976 | } |
| 977 | 977 | |
| 978 | - $k = count( $extension_sections ) - 1 ; |
|
| 979 | - $extension_sections[ $k ]['fields'][] = $button; |
|
| 978 | + $k = count( $extension_sections ) - 1 ; |
|
| 979 | + $extension_sections[ $k ]['fields'][] = $button; |
|
| 980 | 980 | $sections = array_merge( $sections, $extension_sections ); |
| 981 | 981 | } else { |
| 982 | - // add the 'update settings' button to the general section |
|
| 983 | - $sections[0]['fields'][] = $button; |
|
| 984 | - } |
|
| 982 | + // add the 'update settings' button to the general section |
|
| 983 | + $sections[0]['fields'][] = $button; |
|
| 984 | + } |
|
| 985 | 985 | |
| 986 | 986 | return $sections; |
| 987 | 987 | } |
@@ -20,16 +20,16 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
| 22 | 22 | |
| 23 | - unset( $field_options['search_filter'] ); |
|
| 23 | + unset( $field_options[ 'search_filter' ] ); |
|
| 24 | 24 | |
| 25 | - if( 'edit' === $context ) { |
|
| 25 | + if ( 'edit' === $context ) { |
|
| 26 | 26 | return $field_options; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - $add_options['link_to_file'] = array( |
|
| 29 | + $add_options[ 'link_to_file' ] = array( |
|
| 30 | 30 | 'type' => 'checkbox', |
| 31 | 31 | 'label' => __( 'Display as a Link:', 'gravityview' ), |
| 32 | - 'desc' => __('Display the uploaded files as links, rather than embedded content.', 'gravityview'), |
|
| 32 | + 'desc' => __( 'Display the uploaded files as links, rather than embedded content.', 'gravityview' ), |
|
| 33 | 33 | 'value' => false, |
| 34 | 34 | 'merge_tags' => false, |
| 35 | 35 | ); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $output_arr = array(); |
| 66 | 66 | |
| 67 | 67 | // Get an array of file paths for the field. |
| 68 | - $file_paths = rgar( $field , 'multipleFiles' ) ? json_decode( $value ) : array( $value ); |
|
| 68 | + $file_paths = rgar( $field, 'multipleFiles' ) ? json_decode( $value ) : array( $value ); |
|
| 69 | 69 | |
| 70 | 70 | // The $value JSON was probably truncated; let's check lead_detail_long. |
| 71 | 71 | if ( ! is_array( $file_paths ) ) { |
@@ -79,19 +79,19 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // Process each file path |
| 82 | - foreach( $file_paths as $file_path ) { |
|
| 82 | + foreach ( $file_paths as $file_path ) { |
|
| 83 | 83 | |
| 84 | 84 | // If the site is HTTPS, use HTTPS |
| 85 | - if(function_exists('set_url_scheme')) { $file_path = set_url_scheme($file_path); } |
|
| 85 | + if ( function_exists( 'set_url_scheme' ) ) { $file_path = set_url_scheme( $file_path ); } |
|
| 86 | 86 | |
| 87 | 87 | // This is from Gravity Forms's code |
| 88 | - $file_path = esc_attr(str_replace(" ", "%20", $file_path)); |
|
| 88 | + $file_path = esc_attr( str_replace( " ", "%20", $file_path ) ); |
|
| 89 | 89 | |
| 90 | 90 | // If the field is set to link to the single entry, link to it. |
| 91 | - $link = !empty( $field_settings['show_as_link'] ) ? GravityView_API::entry_link( $entry, $field ) : $file_path; |
|
| 91 | + $link = ! empty( $field_settings[ 'show_as_link' ] ) ? GravityView_API::entry_link( $entry, $field ) : $file_path; |
|
| 92 | 92 | |
| 93 | 93 | // Get file path information |
| 94 | - $file_path_info = pathinfo($file_path); |
|
| 94 | + $file_path_info = pathinfo( $file_path ); |
|
| 95 | 95 | |
| 96 | 96 | $html_format = NULL; |
| 97 | 97 | |
@@ -100,30 +100,30 @@ discard block |
||
| 100 | 100 | $disable_wrapped_link = false; |
| 101 | 101 | |
| 102 | 102 | // Is this an image? |
| 103 | - $image = new GravityView_Image(array( |
|
| 103 | + $image = new GravityView_Image( array( |
|
| 104 | 104 | 'src' => $file_path, |
| 105 | - 'class' => 'gv-image gv-field-id-'.$field_settings['id'], |
|
| 106 | - 'alt' => $field_settings['label'], |
|
| 107 | - 'width' => (gravityview_get_context() === 'single' ? NULL : 250) |
|
| 108 | - )); |
|
| 105 | + 'class' => 'gv-image gv-field-id-' . $field_settings[ 'id' ], |
|
| 106 | + 'alt' => $field_settings[ 'label' ], |
|
| 107 | + 'width' => ( gravityview_get_context() === 'single' ? NULL : 250 ) |
|
| 108 | + ) ); |
|
| 109 | 109 | |
| 110 | 110 | $content = $image->html(); |
| 111 | 111 | |
| 112 | 112 | // The new default content is the image, if it exists. If not, use the file name as the content. |
| 113 | - $content = !empty( $content ) ? $content : $file_path_info['basename']; |
|
| 113 | + $content = ! empty( $content ) ? $content : $file_path_info[ 'basename' ]; |
|
| 114 | 114 | |
| 115 | 115 | // If pathinfo() gave us the extension of the file, run the switch statement using that. |
| 116 | - $extension = empty( $file_path_info['extension'] ) ? NULL : strtolower( $file_path_info['extension'] ); |
|
| 116 | + $extension = empty( $file_path_info[ 'extension' ] ) ? NULL : strtolower( $file_path_info[ 'extension' ] ); |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - switch( true ) { |
|
| 119 | + switch ( true ) { |
|
| 120 | 120 | |
| 121 | 121 | // Audio file |
| 122 | 122 | case in_array( $extension, wp_get_audio_extensions() ): |
| 123 | 123 | |
| 124 | 124 | $disable_lightbox = true; |
| 125 | 125 | |
| 126 | - if( shortcode_exists( 'audio' ) ) { |
|
| 126 | + if ( shortcode_exists( 'audio' ) ) { |
|
| 127 | 127 | |
| 128 | 128 | $disable_wrapped_link = true; |
| 129 | 129 | |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | $audio_settings = apply_filters( 'gravityview_audio_settings', array( |
| 136 | 136 | 'src' => $file_path, |
| 137 | - 'class' => 'wp-audio-shortcode gv-audio gv-field-id-'.$field_settings['id'] |
|
| 138 | - )); |
|
| 137 | + 'class' => 'wp-audio-shortcode gv-audio gv-field-id-' . $field_settings[ 'id' ] |
|
| 138 | + ) ); |
|
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * Generate the audio shortcode |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | $disable_lightbox = true; |
| 155 | 155 | |
| 156 | - if( shortcode_exists( 'video' ) ) { |
|
| 156 | + if ( shortcode_exists( 'video' ) ) { |
|
| 157 | 157 | |
| 158 | 158 | $disable_wrapped_link = true; |
| 159 | 159 | |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | $video_settings = apply_filters( 'gravityview_video_settings', array( |
| 166 | 166 | 'src' => $file_path, |
| 167 | - 'class' => 'wp-video-shortcode gv-video gv-field-id-'.$field_settings['id'] |
|
| 168 | - )); |
|
| 167 | + 'class' => 'wp-video-shortcode gv-video gv-field-id-' . $field_settings[ 'id' ] |
|
| 168 | + ) ); |
|
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | 171 | * Generate the video shortcode |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | break; |
| 188 | 188 | |
| 189 | 189 | // if not image, do not set the lightbox (@since 1.5.3) |
| 190 | - case !in_array( $extension, array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ) ): |
|
| 190 | + case ! in_array( $extension, array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ) ): |
|
| 191 | 191 | |
| 192 | 192 | $disable_lightbox = true; |
| 193 | 193 | |
@@ -197,10 +197,10 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | // If using Link to File, override the content. |
| 199 | 199 | // (We do this here so that the $disable_lightbox can be set. Yes, there's a little more processing time, but oh well.) |
| 200 | - if( !empty( $field_settings['link_to_file'] ) ) { |
|
| 200 | + if ( ! empty( $field_settings[ 'link_to_file' ] ) ) { |
|
| 201 | 201 | |
| 202 | 202 | // Force the content to be the file name |
| 203 | - $content = $file_path_info["basename"]; |
|
| 203 | + $content = $file_path_info[ "basename" ]; |
|
| 204 | 204 | |
| 205 | 205 | // Restore the wrapped link |
| 206 | 206 | $disable_wrapped_link = false; |
@@ -208,13 +208,13 @@ discard block |
||
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // Whether to use lightbox or not |
| 211 | - if( $disable_lightbox || empty( $gravityview_view->atts['lightbox'] ) || !empty( $field_settings['show_as_link'] ) ) { |
|
| 211 | + if ( $disable_lightbox || empty( $gravityview_view->atts[ 'lightbox' ] ) || ! empty( $field_settings[ 'show_as_link' ] ) ) { |
|
| 212 | 212 | |
| 213 | - $link_atts = empty( $field_settings['show_as_link'] ) ? array( 'target' => '_blank' ) : array(); |
|
| 213 | + $link_atts = empty( $field_settings[ 'show_as_link' ] ) ? array( 'target' => '_blank' ) : array(); |
|
| 214 | 214 | |
| 215 | 215 | } else { |
| 216 | 216 | |
| 217 | - $entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry ); |
|
| 217 | + $entry_slug = GravityView_API::get_entry_slug( $entry[ 'id' ], $entry ); |
|
| 218 | 218 | |
| 219 | 219 | $link_atts = array( |
| 220 | 220 | 'rel' => sprintf( "%s-%s", $gv_class, $entry_slug ), |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $disable_wrapped_link = apply_filters( 'gravityview/fields/fileupload/disable_link', $disable_wrapped_link, $gravityview_view->getCurrentField() ); |
| 241 | 241 | |
| 242 | 242 | // If the HTML output hasn't been overridden by the switch statement above, use the default format |
| 243 | - if( !empty( $content ) && empty( $disable_wrapped_link ) ) { |
|
| 243 | + if ( ! empty( $content ) && empty( $disable_wrapped_link ) ) { |
|
| 244 | 244 | |
| 245 | 245 | /** |
| 246 | 246 | * Modify the link text (defaults to the file name) |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | $content = gravityview_get_link( $link, $content, $link_atts ); |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - $output_arr[] = array( |
|
| 258 | + $output_arr[ ] = array( |
|
| 259 | 259 | 'file_path' => $file_path, |
| 260 | 260 | 'content' => $content |
| 261 | 261 | ); |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * If the user doesn't have the `gravityview_support_port` capability, returns false; then |
| 223 | 223 | * If global setting is "hide", returns false; then |
| 224 | - * If user preference is not set, return global setting; then |
|
| 225 | - * If user preference is set, return that setting. |
|
| 224 | + * If user preference is not set, return global setting; then |
|
| 225 | + * If user preference is set, return that setting. |
|
| 226 | 226 | * |
| 227 | 227 | * @since 1.15 |
| 228 | - * @since 1.17.5 Changed behavior to respect global setting |
|
| 228 | + * @since 1.17.5 Changed behavior to respect global setting |
|
| 229 | 229 | * |
| 230 | 230 | * @param int $user Optional. ID of the user to check, defaults to 0 for current user. |
| 231 | 231 | * |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $global_setting = GravityView_Settings::getSetting( 'support_port' ); |
| 241 | 241 | |
| 242 | 242 | if ( empty( $global_setting ) ) { |
| 243 | - return false; |
|
| 243 | + return false; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Get the per-user Support Port setting |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * Modifies the output of profile.php to add GravityView Support preference |
| 277 | 277 | * |
| 278 | 278 | * @since 1.15 |
| 279 | - * @since 1.17.5 Only show if global setting is active |
|
| 279 | + * @since 1.17.5 Only show if global setting is active |
|
| 280 | 280 | * |
| 281 | 281 | * @param WP_User $user Current user info |
| 282 | 282 | * |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | $global_setting = GravityView_Settings::getSetting( 'support_port' ); |
| 288 | 288 | |
| 289 | 289 | if ( empty( $global_setting ) ) { |
| 290 | - return; |
|
| 290 | + return; |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |