| @@ -11,7 +11,7 @@ discard block | ||
| 11 | 11 | */ | 
| 12 | 12 | |
| 13 | 13 |  if ( ! defined( 'WPINC' ) ) { | 
| 14 | - die; | |
| 14 | + die; | |
| 15 | 15 | } | 
| 16 | 16 | |
| 17 | 17 | /** | 
| @@ -22,255 +22,255 @@ discard block | ||
| 22 | 22 | /** | 
| 23 | 23 | * @var GravityView_Edit_Entry | 
| 24 | 24 | */ | 
| 25 | - protected $loader; | |
| 25 | + protected $loader; | |
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * @var WP_User|null Temporary storage used by restore_user_details() | |
| 29 | - */ | |
| 30 | - private $_user_before_update = null; | |
| 27 | + /** | |
| 28 | + * @var WP_User|null Temporary storage used by restore_user_details() | |
| 29 | + */ | |
| 30 | + private $_user_before_update = null; | |
| 31 | 31 | |
| 32 | -    function __construct( GravityView_Edit_Entry $loader ) { | |
| 33 | - $this->loader = $loader; | |
| 34 | - } | |
| 32 | +	function __construct( GravityView_Edit_Entry $loader ) { | |
| 33 | + $this->loader = $loader; | |
| 34 | + } | |
| 35 | 35 | |
| 36 | 36 | /** | 
| 37 | 37 | * @since 1.11 | 
| 38 | 38 | */ | 
| 39 | 39 |  	public function load() { | 
| 40 | 40 | |
| 41 | - /** | |
| 42 | - * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? | |
| 43 | - * @since 1.11 | |
| 44 | - * @param boolean $boolean Whether to trigger update on user registration (default: true) | |
| 45 | - */ | |
| 46 | -        if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { | |
| 47 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); | |
| 48 | - | |
| 49 | - // last resort in case the current user display name don't match any of the defaults | |
| 50 | - add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); | |
| 51 | - } | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * Update the WordPress user profile based on the GF User Registration create feed | |
| 56 | - * | |
| 57 | - * @since 1.11 | |
| 58 | - * | |
| 59 | - * @param array $form Gravity Forms form array | |
| 60 | - * @param string $entry_id Gravity Forms entry ID | |
| 61 | - * @return void | |
| 62 | - */ | |
| 63 | -    public function update_user( $form = array(), $entry_id = 0 ) { | |
| 64 | - | |
| 65 | -        if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) { | |
| 66 | - return; | |
| 67 | - } | |
| 68 | - | |
| 69 | - // support for GF User Registration 3.x | |
| 70 | -        $gf_user_3 =  class_exists('GF_User_Registration') ? true : false; | |
| 71 | - | |
| 72 | -        if( $gf_user_3 ) { | |
| 73 | - $gf_user_registration = GF_User_Registration::get_instance(); | |
| 74 | - } | |
| 75 | - | |
| 76 | - $entry = GFAPI::get_entry( $entry_id ); | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on | |
| 80 | - * @since 1.11 | |
| 81 | - * @param array $entry Gravity Forms entry | |
| 82 | - * @param array $form Gravity Forms form | |
| 83 | - */ | |
| 84 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @since 1.14 | |
| 88 | - */ | |
| 89 | -        if( $gf_user_3 ) { | |
| 90 | - $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); | |
| 91 | -        } else { | |
| 92 | - $config = GFUser::get_active_config( $form, $entry ); | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed | |
| 97 | - * @since 1.15 | |
| 98 | - * @param[in,out] boolean $preserve_role Preserve current user role Default: true | |
| 99 | - * @param[in] array $config Gravity Forms User Registration feed configuration for the form | |
| 100 | - * @param[in] array $form Gravity Forms form array | |
| 101 | - * @param[in] array $entry Gravity Forms entry being edited | |
| 102 | - */ | |
| 103 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); | |
| 104 | - | |
| 105 | -        if( $preserve_role ) { | |
| 106 | - $config['meta']['role'] = 'gfur_preserve_role'; | |
| 107 | - } | |
| 108 | - | |
| 109 | - /** | |
| 110 | - * Make sure the current display name is not changed with the update user method. | |
| 111 | - * @since 1.15 | |
| 112 | - */ | |
| 113 | - $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); | |
| 114 | - | |
| 115 | - | |
| 116 | - /** | |
| 117 | - * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration | |
| 118 | - * @since 1.14 | |
| 119 | - * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form | |
| 120 | - * @param[in] array $form Gravity Forms form array | |
| 121 | - * @param[in] array $entry Gravity Forms entry being edited | |
| 122 | - */ | |
| 123 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); | |
| 124 | - | |
| 125 | - | |
| 126 | - $feed_pos = $gf_user_3 ? 'meta/feedType' : 'meta/feed_type'; | |
| 127 | - $is_create_feed = ( $config && rgars( $config, $feed_pos ) === 'create' ); | |
| 128 | - | |
| 129 | - // Only update if it's a create feed | |
| 130 | -        if( ! $is_create_feed ) { | |
| 131 | - return; | |
| 132 | - } | |
| 133 | - | |
| 134 | - // The priority is set to 3 so that default priority (10) will still override it | |
| 135 | - add_filter( 'send_password_change_email', '__return_false', 3 ); | |
| 136 | - add_filter( 'send_email_change_email', '__return_false', 3 ); | |
| 137 | - | |
| 138 | - // Trigger the User Registration update user method | |
| 139 | -        if( $gf_user_3 ) { | |
| 140 | - $gf_user_registration->update_user( $entry, $form, $config ); | |
| 141 | -        } else { | |
| 142 | - GFUser::update_user( $entry, $form, $config ); | |
| 143 | - } | |
| 144 | - | |
| 145 | - | |
| 146 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); | |
| 147 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); | |
| 148 | - | |
| 149 | - } | |
| 150 | - | |
| 151 | - /** | |
| 152 | - * Calculate the user display name format | |
| 153 | - * | |
| 154 | - * @since 1.15 | |
| 155 | - * | |
| 156 | - * @param int $user_id WP User ID | |
| 157 | - * @return string Display name format as used inside Gravity Forms User Registration | |
| 158 | - */ | |
| 159 | -    public function match_current_display_name( $user_id ) { | |
| 160 | - | |
| 161 | - $user = get_userdata( $user_id ); | |
| 162 | - | |
| 163 | - $names = $this->generate_display_names( $user ); | |
| 164 | - | |
| 165 | - $format = array_search( $user->display_name, $names, true ); | |
| 166 | - | |
| 167 | - // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) | |
| 168 | - // trigger last resort method at the 'gform_user_updated' hook | |
| 169 | -        if( false === $format || 'nickname' === $format ) { | |
| 170 | - $this->_user_before_update = $user; | |
| 171 | - $format = 'nickname'; | |
| 172 | - } | |
| 173 | - | |
| 174 | - return $format; | |
| 175 | - | |
| 176 | - } | |
| 177 | - | |
| 178 | - /** | |
| 179 | - * Generate an array of all the user display names possibilities | |
| 180 | - * | |
| 181 | - * @since 1.15 | |
| 182 | - * | |
| 183 | - * @param object $profileuser WP_User object | |
| 184 | - * @return array List all the possible display names for a certain User object | |
| 185 | - */ | |
| 186 | -    public function generate_display_names( $profileuser ) { | |
| 187 | - | |
| 188 | - $public_display = array(); | |
| 189 | - $public_display['nickname'] = $profileuser->nickname; | |
| 190 | - $public_display['username'] = $profileuser->user_login; | |
| 191 | - | |
| 192 | - if ( !empty($profileuser->first_name) ) | |
| 193 | - $public_display['firstname'] = $profileuser->first_name; | |
| 194 | - | |
| 195 | - if ( !empty($profileuser->last_name) ) | |
| 196 | - $public_display['lastname'] = $profileuser->last_name; | |
| 197 | - | |
| 198 | -        if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { | |
| 199 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; | |
| 200 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; | |
| 201 | - } | |
| 202 | - | |
| 203 | - $public_display = array_map( 'trim', $public_display ); | |
| 204 | - $public_display = array_unique( $public_display ); | |
| 205 | - | |
| 206 | - return $public_display; | |
| 207 | - } | |
| 208 | - | |
| 209 | - | |
| 210 | - /** | |
| 211 | - * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon | |
| 212 | - * | |
| 213 | - * @see GFUser::update_user() | |
| 214 | - * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon | |
| 215 | - * @param array $config Gravity Forms User Registration Addon form feed configuration | |
| 216 | - * @param array $entry The Gravity Forms entry that was just updated | |
| 217 | - * @param string $password User password | |
| 218 | - * @return void | |
| 219 | - */ | |
| 220 | -    public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { | |
| 221 | - | |
| 222 | - /** | |
| 223 | - * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. | |
| 224 | - * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed | |
| 225 | - * @since 1.14.4 | |
| 226 | - * @param boolean $restore_display_name Restore Display Name? Default: true | |
| 227 | - */ | |
| 228 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); | |
| 229 | - | |
| 230 | - $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); | |
| 231 | - | |
| 232 | - /** | |
| 233 | - * Don't restore display name: | |
| 234 | - * - either disabled, | |
| 235 | - * - or it is an Update feed (we only care about Create feed) | |
| 236 | - * - or we don't need as we found the correct format before updating user. | |
| 237 | - * @since 1.14.4 | |
| 238 | - */ | |
| 239 | -        if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { | |
| 240 | - return; | |
| 241 | - } | |
| 242 | - | |
| 243 | - $user_after_update = get_userdata( $user_id ); | |
| 244 | - | |
| 245 | - $restored_user = $user_after_update; | |
| 246 | - | |
| 247 | - // Restore previous display_name | |
| 248 | - $restored_user->display_name = $this->_user_before_update->display_name; | |
| 249 | - | |
| 250 | - // Don't have WP update the password. | |
| 251 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); | |
| 252 | - | |
| 253 | - /** | |
| 254 | - * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView | |
| 255 | - * @since 1.14 | |
| 256 | - * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() | |
| 257 | - * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration | |
| 258 | - * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration | |
| 259 | - * @param array $entry The Gravity Forms entry that was just updated | |
| 260 | - */ | |
| 261 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); | |
| 262 | - | |
| 263 | - $updated = wp_update_user( $restored_user ); | |
| 264 | - | |
| 265 | -        if( is_wp_error( $updated ) ) { | |
| 266 | -            do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); | |
| 267 | -        } else { | |
| 268 | -            do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); | |
| 269 | - } | |
| 270 | - | |
| 271 | - $this->_user_before_update = null; | |
| 272 | - | |
| 273 | - unset( $updated, $restored_user, $user_after_update ); | |
| 274 | - } | |
| 41 | + /** | |
| 42 | + * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? | |
| 43 | + * @since 1.11 | |
| 44 | + * @param boolean $boolean Whether to trigger update on user registration (default: true) | |
| 45 | + */ | |
| 46 | +		if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { | |
| 47 | + add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); | |
| 48 | + | |
| 49 | + // last resort in case the current user display name don't match any of the defaults | |
| 50 | + add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Update the WordPress user profile based on the GF User Registration create feed | |
| 56 | + * | |
| 57 | + * @since 1.11 | |
| 58 | + * | |
| 59 | + * @param array $form Gravity Forms form array | |
| 60 | + * @param string $entry_id Gravity Forms entry ID | |
| 61 | + * @return void | |
| 62 | + */ | |
| 63 | +	public function update_user( $form = array(), $entry_id = 0 ) { | |
| 64 | + | |
| 65 | +		if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) { | |
| 66 | + return; | |
| 67 | + } | |
| 68 | + | |
| 69 | + // support for GF User Registration 3.x | |
| 70 | +		$gf_user_3 =  class_exists('GF_User_Registration') ? true : false; | |
| 71 | + | |
| 72 | +		if( $gf_user_3 ) { | |
| 73 | + $gf_user_registration = GF_User_Registration::get_instance(); | |
| 74 | + } | |
| 75 | + | |
| 76 | + $entry = GFAPI::get_entry( $entry_id ); | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on | |
| 80 | + * @since 1.11 | |
| 81 | + * @param array $entry Gravity Forms entry | |
| 82 | + * @param array $form Gravity Forms form | |
| 83 | + */ | |
| 84 | + $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @since 1.14 | |
| 88 | + */ | |
| 89 | +		if( $gf_user_3 ) { | |
| 90 | + $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); | |
| 91 | +		} else { | |
| 92 | + $config = GFUser::get_active_config( $form, $entry ); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed | |
| 97 | + * @since 1.15 | |
| 98 | + * @param[in,out] boolean $preserve_role Preserve current user role Default: true | |
| 99 | + * @param[in] array $config Gravity Forms User Registration feed configuration for the form | |
| 100 | + * @param[in] array $form Gravity Forms form array | |
| 101 | + * @param[in] array $entry Gravity Forms entry being edited | |
| 102 | + */ | |
| 103 | + $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); | |
| 104 | + | |
| 105 | +		if( $preserve_role ) { | |
| 106 | + $config['meta']['role'] = 'gfur_preserve_role'; | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Make sure the current display name is not changed with the update user method. | |
| 111 | + * @since 1.15 | |
| 112 | + */ | |
| 113 | + $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); | |
| 114 | + | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration | |
| 118 | + * @since 1.14 | |
| 119 | + * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form | |
| 120 | + * @param[in] array $form Gravity Forms form array | |
| 121 | + * @param[in] array $entry Gravity Forms entry being edited | |
| 122 | + */ | |
| 123 | + $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); | |
| 124 | + | |
| 125 | + | |
| 126 | + $feed_pos = $gf_user_3 ? 'meta/feedType' : 'meta/feed_type'; | |
| 127 | + $is_create_feed = ( $config && rgars( $config, $feed_pos ) === 'create' ); | |
| 128 | + | |
| 129 | + // Only update if it's a create feed | |
| 130 | +		if( ! $is_create_feed ) { | |
| 131 | + return; | |
| 132 | + } | |
| 133 | + | |
| 134 | + // The priority is set to 3 so that default priority (10) will still override it | |
| 135 | + add_filter( 'send_password_change_email', '__return_false', 3 ); | |
| 136 | + add_filter( 'send_email_change_email', '__return_false', 3 ); | |
| 137 | + | |
| 138 | + // Trigger the User Registration update user method | |
| 139 | +		if( $gf_user_3 ) { | |
| 140 | + $gf_user_registration->update_user( $entry, $form, $config ); | |
| 141 | +		} else { | |
| 142 | + GFUser::update_user( $entry, $form, $config ); | |
| 143 | + } | |
| 144 | + | |
| 145 | + | |
| 146 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); | |
| 147 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); | |
| 148 | + | |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Calculate the user display name format | |
| 153 | + * | |
| 154 | + * @since 1.15 | |
| 155 | + * | |
| 156 | + * @param int $user_id WP User ID | |
| 157 | + * @return string Display name format as used inside Gravity Forms User Registration | |
| 158 | + */ | |
| 159 | +	public function match_current_display_name( $user_id ) { | |
| 160 | + | |
| 161 | + $user = get_userdata( $user_id ); | |
| 162 | + | |
| 163 | + $names = $this->generate_display_names( $user ); | |
| 164 | + | |
| 165 | + $format = array_search( $user->display_name, $names, true ); | |
| 166 | + | |
| 167 | + // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) | |
| 168 | + // trigger last resort method at the 'gform_user_updated' hook | |
| 169 | +		if( false === $format || 'nickname' === $format ) { | |
| 170 | + $this->_user_before_update = $user; | |
| 171 | + $format = 'nickname'; | |
| 172 | + } | |
| 173 | + | |
| 174 | + return $format; | |
| 175 | + | |
| 176 | + } | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * Generate an array of all the user display names possibilities | |
| 180 | + * | |
| 181 | + * @since 1.15 | |
| 182 | + * | |
| 183 | + * @param object $profileuser WP_User object | |
| 184 | + * @return array List all the possible display names for a certain User object | |
| 185 | + */ | |
| 186 | +	public function generate_display_names( $profileuser ) { | |
| 187 | + | |
| 188 | + $public_display = array(); | |
| 189 | + $public_display['nickname'] = $profileuser->nickname; | |
| 190 | + $public_display['username'] = $profileuser->user_login; | |
| 191 | + | |
| 192 | + if ( !empty($profileuser->first_name) ) | |
| 193 | + $public_display['firstname'] = $profileuser->first_name; | |
| 194 | + | |
| 195 | + if ( !empty($profileuser->last_name) ) | |
| 196 | + $public_display['lastname'] = $profileuser->last_name; | |
| 197 | + | |
| 198 | +		if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { | |
| 199 | + $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; | |
| 200 | + $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; | |
| 201 | + } | |
| 202 | + | |
| 203 | + $public_display = array_map( 'trim', $public_display ); | |
| 204 | + $public_display = array_unique( $public_display ); | |
| 205 | + | |
| 206 | + return $public_display; | |
| 207 | + } | |
| 208 | + | |
| 209 | + | |
| 210 | + /** | |
| 211 | + * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon | |
| 212 | + * | |
| 213 | + * @see GFUser::update_user() | |
| 214 | + * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon | |
| 215 | + * @param array $config Gravity Forms User Registration Addon form feed configuration | |
| 216 | + * @param array $entry The Gravity Forms entry that was just updated | |
| 217 | + * @param string $password User password | |
| 218 | + * @return void | |
| 219 | + */ | |
| 220 | +	public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { | |
| 221 | + | |
| 222 | + /** | |
| 223 | + * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. | |
| 224 | + * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed | |
| 225 | + * @since 1.14.4 | |
| 226 | + * @param boolean $restore_display_name Restore Display Name? Default: true | |
| 227 | + */ | |
| 228 | + $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); | |
| 229 | + | |
| 230 | + $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); | |
| 231 | + | |
| 232 | + /** | |
| 233 | + * Don't restore display name: | |
| 234 | + * - either disabled, | |
| 235 | + * - or it is an Update feed (we only care about Create feed) | |
| 236 | + * - or we don't need as we found the correct format before updating user. | |
| 237 | + * @since 1.14.4 | |
| 238 | + */ | |
| 239 | +		if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { | |
| 240 | + return; | |
| 241 | + } | |
| 242 | + | |
| 243 | + $user_after_update = get_userdata( $user_id ); | |
| 244 | + | |
| 245 | + $restored_user = $user_after_update; | |
| 246 | + | |
| 247 | + // Restore previous display_name | |
| 248 | + $restored_user->display_name = $this->_user_before_update->display_name; | |
| 249 | + | |
| 250 | + // Don't have WP update the password. | |
| 251 | + unset( $restored_user->data->user_pass, $restored_user->user_pass ); | |
| 252 | + | |
| 253 | + /** | |
| 254 | + * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView | |
| 255 | + * @since 1.14 | |
| 256 | + * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() | |
| 257 | + * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration | |
| 258 | + * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration | |
| 259 | + * @param array $entry The Gravity Forms entry that was just updated | |
| 260 | + */ | |
| 261 | + $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); | |
| 262 | + | |
| 263 | + $updated = wp_update_user( $restored_user ); | |
| 264 | + | |
| 265 | +		if( is_wp_error( $updated ) ) { | |
| 266 | +			do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); | |
| 267 | +		} else { | |
| 268 | +			do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); | |
| 269 | + } | |
| 270 | + | |
| 271 | + $this->_user_before_update = null; | |
| 272 | + | |
| 273 | + unset( $updated, $restored_user, $user_after_update ); | |
| 274 | + } | |
| 275 | 275 | |
| 276 | 276 | } //end class | 
| @@ -43,8 +43,8 @@ discard block | ||
| 43 | 43 | * @since 1.11 | 
| 44 | 44 | * @param boolean $boolean Whether to trigger update on user registration (default: true) | 
| 45 | 45 | */ | 
| 46 | -        if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { | |
| 47 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); | |
| 46 | +        if ( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { | |
| 47 | + add_action( 'gravityview/edit_entry/after_update', array( $this, 'update_user' ), 10, 2 ); | |
| 48 | 48 | |
| 49 | 49 | // last resort in case the current user display name don't match any of the defaults | 
| 50 | 50 | add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); | 
| @@ -62,14 +62,14 @@ discard block | ||
| 62 | 62 | */ | 
| 63 | 63 |      public function update_user( $form = array(), $entry_id = 0 ) { | 
| 64 | 64 | |
| 65 | -        if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) { | |
| 65 | +        if ( ! class_exists( 'GFAPI' ) || ! class_exists( 'GFUser' ) || empty( $entry_id ) ) { | |
| 66 | 66 | return; | 
| 67 | 67 | } | 
| 68 | 68 | |
| 69 | 69 | // support for GF User Registration 3.x | 
| 70 | -        $gf_user_3 =  class_exists('GF_User_Registration') ? true : false; | |
| 70 | + $gf_user_3 = class_exists( 'GF_User_Registration' ) ? true : false; | |
| 71 | 71 | |
| 72 | -        if( $gf_user_3 ) { | |
| 72 | +        if ( $gf_user_3 ) { | |
| 73 | 73 | $gf_user_registration = GF_User_Registration::get_instance(); | 
| 74 | 74 | } | 
| 75 | 75 | |
| @@ -86,7 +86,7 @@ discard block | ||
| 86 | 86 | /** | 
| 87 | 87 | * @since 1.14 | 
| 88 | 88 | */ | 
| 89 | -        if( $gf_user_3 ) { | |
| 89 | +        if ( $gf_user_3 ) { | |
| 90 | 90 | $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); | 
| 91 | 91 |          } else { | 
| 92 | 92 | $config = GFUser::get_active_config( $form, $entry ); | 
| @@ -102,15 +102,15 @@ discard block | ||
| 102 | 102 | */ | 
| 103 | 103 | $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); | 
| 104 | 104 | |
| 105 | -        if( $preserve_role ) { | |
| 106 | - $config['meta']['role'] = 'gfur_preserve_role'; | |
| 105 | +        if ( $preserve_role ) { | |
| 106 | + $config[ 'meta' ][ 'role' ] = 'gfur_preserve_role'; | |
| 107 | 107 | } | 
| 108 | 108 | |
| 109 | 109 | /** | 
| 110 | 110 | * Make sure the current display name is not changed with the update user method. | 
| 111 | 111 | * @since 1.15 | 
| 112 | 112 | */ | 
| 113 | - $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); | |
| 113 | + $config[ 'meta' ][ 'displayname' ] = $this->match_current_display_name( $entry[ 'created_by' ] ); | |
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | /** | 
| @@ -127,7 +127,7 @@ discard block | ||
| 127 | 127 | $is_create_feed = ( $config && rgars( $config, $feed_pos ) === 'create' ); | 
| 128 | 128 | |
| 129 | 129 | // Only update if it's a create feed | 
| 130 | -        if( ! $is_create_feed ) { | |
| 130 | +        if ( ! $is_create_feed ) { | |
| 131 | 131 | return; | 
| 132 | 132 | } | 
| 133 | 133 | |
| @@ -136,7 +136,7 @@ discard block | ||
| 136 | 136 | add_filter( 'send_email_change_email', '__return_false', 3 ); | 
| 137 | 137 | |
| 138 | 138 | // Trigger the User Registration update user method | 
| 139 | -        if( $gf_user_3 ) { | |
| 139 | +        if ( $gf_user_3 ) { | |
| 140 | 140 | $gf_user_registration->update_user( $entry, $form, $config ); | 
| 141 | 141 |          } else { | 
| 142 | 142 | GFUser::update_user( $entry, $form, $config ); | 
| @@ -166,7 +166,7 @@ discard block | ||
| 166 | 166 | |
| 167 | 167 | // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) | 
| 168 | 168 | // trigger last resort method at the 'gform_user_updated' hook | 
| 169 | -        if( false === $format || 'nickname' === $format ) { | |
| 169 | +        if ( false === $format || 'nickname' === $format ) { | |
| 170 | 170 | $this->_user_before_update = $user; | 
| 171 | 171 | $format = 'nickname'; | 
| 172 | 172 | } | 
| @@ -186,18 +186,18 @@ discard block | ||
| 186 | 186 |      public function generate_display_names( $profileuser ) { | 
| 187 | 187 | |
| 188 | 188 | $public_display = array(); | 
| 189 | - $public_display['nickname'] = $profileuser->nickname; | |
| 190 | - $public_display['username'] = $profileuser->user_login; | |
| 189 | + $public_display[ 'nickname' ] = $profileuser->nickname; | |
| 190 | + $public_display[ 'username' ] = $profileuser->user_login; | |
| 191 | 191 | |
| 192 | - if ( !empty($profileuser->first_name) ) | |
| 193 | - $public_display['firstname'] = $profileuser->first_name; | |
| 192 | + if ( ! empty( $profileuser->first_name ) ) | |
| 193 | + $public_display[ 'firstname' ] = $profileuser->first_name; | |
| 194 | 194 | |
| 195 | - if ( !empty($profileuser->last_name) ) | |
| 196 | - $public_display['lastname'] = $profileuser->last_name; | |
| 195 | + if ( ! empty( $profileuser->last_name ) ) | |
| 196 | + $public_display[ 'lastname' ] = $profileuser->last_name; | |
| 197 | 197 | |
| 198 | -        if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { | |
| 199 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; | |
| 200 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; | |
| 198 | +        if ( ! empty( $profileuser->first_name ) && ! empty( $profileuser->last_name ) ) { | |
| 199 | + $public_display[ 'firstlast' ] = $profileuser->first_name . ' ' . $profileuser->last_name; | |
| 200 | + $public_display[ 'lastfirst' ] = $profileuser->last_name . ' ' . $profileuser->first_name; | |
| 201 | 201 | } | 
| 202 | 202 | |
| 203 | 203 | $public_display = array_map( 'trim', $public_display ); | 
| @@ -227,7 +227,7 @@ discard block | ||
| 227 | 227 | */ | 
| 228 | 228 | $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); | 
| 229 | 229 | |
| 230 | - $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); | |
| 230 | + $is_update_feed = ( $config && rgars( $config, 'meta/feed_type' ) === 'update' ); | |
| 231 | 231 | |
| 232 | 232 | /** | 
| 233 | 233 | * Don't restore display name: | 
| @@ -236,7 +236,7 @@ discard block | ||
| 236 | 236 | * - or we don't need as we found the correct format before updating user. | 
| 237 | 237 | * @since 1.14.4 | 
| 238 | 238 | */ | 
| 239 | -        if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { | |
| 239 | +        if ( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { | |
| 240 | 240 | return; | 
| 241 | 241 | } | 
| 242 | 242 | |
| @@ -262,10 +262,10 @@ discard block | ||
| 262 | 262 | |
| 263 | 263 | $updated = wp_update_user( $restored_user ); | 
| 264 | 264 | |
| 265 | -        if( is_wp_error( $updated ) ) { | |
| 266 | -            do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); | |
| 265 | +        if ( is_wp_error( $updated ) ) { | |
| 266 | + do_action( 'gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); | |
| 267 | 267 |          } else { | 
| 268 | -            do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); | |
| 268 | + do_action( 'gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); | |
| 269 | 269 | } | 
| 270 | 270 | |
| 271 | 271 | $this->_user_before_update = null; | 
| @@ -18,80 +18,80 @@ discard block | ||
| 18 | 18 | |
| 19 | 19 |  class GravityView_Edit_Entry { | 
| 20 | 20 | |
| 21 | - /** | |
| 22 | - * @var string | |
| 23 | - */ | |
| 21 | + /** | |
| 22 | + * @var string | |
| 23 | + */ | |
| 24 | 24 | static $file; | 
| 25 | 25 | |
| 26 | 26 | static $instance; | 
| 27 | 27 | |
| 28 | - /** | |
| 29 | - * Component instances. | |
| 30 | - * @var array | |
| 31 | - */ | |
| 32 | - public $instances = array(); | |
| 28 | + /** | |
| 29 | + * Component instances. | |
| 30 | + * @var array | |
| 31 | + */ | |
| 32 | + public $instances = array(); | |
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 |  	function __construct() { | 
| 36 | 36 | |
| 37 | - self::$file = plugin_dir_path( __FILE__ ); | |
| 37 | + self::$file = plugin_dir_path( __FILE__ ); | |
| 38 | 38 | |
| 39 | -        if( is_admin() ) { | |
| 40 | - $this->load_components( 'admin' ); | |
| 41 | - } | |
| 39 | +		if( is_admin() ) { | |
| 40 | + $this->load_components( 'admin' ); | |
| 41 | + } | |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - $this->load_components( 'render' ); | |
| 44 | + $this->load_components( 'render' ); | |
| 45 | 45 | |
| 46 | - // If GF User Registration Add-on exists | |
| 47 | - $this->load_components( 'user-registration' ); | |
| 46 | + // If GF User Registration Add-on exists | |
| 47 | + $this->load_components( 'user-registration' ); | |
| 48 | 48 | |
| 49 | - $this->add_hooks(); | |
| 49 | + $this->add_hooks(); | |
| 50 | 50 | |
| 51 | 51 | // Process hooks for addons that may or may not be present | 
| 52 | 52 | $this->addon_specific_hooks(); | 
| 53 | 53 | } | 
| 54 | 54 | |
| 55 | 55 | |
| 56 | -    static function getInstance() { | |
| 56 | +	static function getInstance() { | |
| 57 | 57 | |
| 58 | -        if( empty( self::$instance ) ) { | |
| 59 | - self::$instance = new GravityView_Edit_Entry; | |
| 60 | - } | |
| 58 | +		if( empty( self::$instance ) ) { | |
| 59 | + self::$instance = new GravityView_Edit_Entry; | |
| 60 | + } | |
| 61 | 61 | |
| 62 | - return self::$instance; | |
| 63 | - } | |
| 62 | + return self::$instance; | |
| 63 | + } | |
| 64 | 64 | |
| 65 | 65 | |
| 66 | -    private function load_components( $component ) { | |
| 66 | +	private function load_components( $component ) { | |
| 67 | 67 | |
| 68 | - $dir = trailingslashit( self::$file ); | |
| 68 | + $dir = trailingslashit( self::$file ); | |
| 69 | 69 | |
| 70 | - $filename = $dir . 'class-edit-entry-' . $component . '.php'; | |
| 71 | - $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); | |
| 70 | + $filename = $dir . 'class-edit-entry-' . $component . '.php'; | |
| 71 | + $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); | |
| 72 | 72 | |
| 73 | - // Loads component and pass extension's instance so that component can | |
| 74 | - // talk each other. | |
| 75 | - require_once $filename; | |
| 76 | - $this->instances[ $component ] = new $classname( $this ); | |
| 77 | - $this->instances[ $component ]->load(); | |
| 73 | + // Loads component and pass extension's instance so that component can | |
| 74 | + // talk each other. | |
| 75 | + require_once $filename; | |
| 76 | + $this->instances[ $component ] = new $classname( $this ); | |
| 77 | + $this->instances[ $component ]->load(); | |
| 78 | 78 | |
| 79 | - } | |
| 79 | + } | |
| 80 | 80 | |
| 81 | -    private function add_hooks() { | |
| 81 | +	private function add_hooks() { | |
| 82 | 82 | |
| 83 | - // Add front-end access to Gravity Forms delete file action | |
| 84 | - add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file') ); | |
| 83 | + // Add front-end access to Gravity Forms delete file action | |
| 84 | + add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file') ); | |
| 85 | 85 | |
| 86 | - // Make sure this hook is run for non-admins | |
| 87 | - add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file') ); | |
| 86 | + // Make sure this hook is run for non-admins | |
| 87 | + add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file') ); | |
| 88 | 88 | |
| 89 | - add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); | |
| 89 | + add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); | |
| 90 | 90 | |
| 91 | - // add template path to check for field | |
| 92 | - add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); | |
| 91 | + // add template path to check for field | |
| 92 | + add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); | |
| 93 | 93 | |
| 94 | - } | |
| 94 | + } | |
| 95 | 95 | |
| 96 | 96 | /** | 
| 97 | 97 | * Trigger hooks that are normally run in the admin for Addons, but need to be triggered manually because we're not in the admin | 
| @@ -105,75 +105,75 @@ discard block | ||
| 105 | 105 | |
| 106 | 106 | } | 
| 107 | 107 | |
| 108 | - /** | |
| 109 | - * Include this extension templates path | |
| 110 | - * @param array $file_paths List of template paths ordered | |
| 111 | - */ | |
| 112 | -    public function add_template_path( $file_paths ) { | |
| 113 | - | |
| 114 | - // Index 100 is the default GravityView template path. | |
| 115 | - $file_paths[ 110 ] = self::$file; | |
| 116 | - | |
| 117 | - return $file_paths; | |
| 118 | - } | |
| 119 | - | |
| 120 | - /** | |
| 121 | - * | |
| 122 | - * Return a well formatted nonce key according to GravityView Edit Entry protocol | |
| 123 | - * | |
| 124 | - * @param $view_id int GravityView view id | |
| 125 | - * @param $form_id int Gravity Forms form id | |
| 126 | - * @param $entry_id int Gravity Forms entry id | |
| 127 | - * @return string | |
| 128 | - */ | |
| 129 | -    public static function get_nonce_key( $view_id, $form_id, $entry_id ) { | |
| 130 | - return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); | |
| 131 | - } | |
| 132 | - | |
| 133 | - | |
| 134 | - /** | |
| 135 | - * The edit entry link creates a secure link with a nonce | |
| 136 | - * | |
| 137 | - * It also mimics the URL structure Gravity Forms expects to have so that | |
| 138 | - * it formats the display of the edit form like it does in the backend, like | |
| 139 | - * "You can edit this post from the post page" fields, for example. | |
| 140 | - * | |
| 141 | - * @param $entry array Gravity Forms entry object | |
| 142 | - * @param $view_id int GravityView view id | |
| 143 | -     * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} | |
| 144 | -     * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } | |
| 145 | - * @return string | |
| 146 | - */ | |
| 147 | -    public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { | |
| 148 | - | |
| 149 | - $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); | |
| 150 | - | |
| 151 | - $base = gv_entry_link( $entry, $post_id ); | |
| 152 | - | |
| 153 | - $url = add_query_arg( array( | |
| 154 | - 'page' => 'gf_entries', // Needed for GFForms::get_page() | |
| 155 | - 'view' => 'entry', // Needed for GFForms::get_page() | |
| 156 | - 'edit' => wp_create_nonce( $nonce_key ) | |
| 157 | - ), $base ); | |
| 158 | - | |
| 159 | - /** | |
| 160 | - * Allow passing params to dynamically populate entry with values | |
| 161 | - * @since 1.9.2 | |
| 162 | - */ | |
| 163 | -	    if( !empty( $field_values ) ) { | |
| 164 | - | |
| 165 | -		    if( is_array( $field_values ) ) { | |
| 166 | - // If already an array, no parse_str() needed | |
| 167 | - $params = $field_values; | |
| 168 | -		    } else { | |
| 169 | - parse_str( $field_values, $params ); | |
| 170 | - } | |
| 171 | - | |
| 172 | - $url = add_query_arg( $params, $url ); | |
| 173 | - } | |
| 174 | - | |
| 175 | - return $url; | |
| 176 | - } | |
| 108 | + /** | |
| 109 | + * Include this extension templates path | |
| 110 | + * @param array $file_paths List of template paths ordered | |
| 111 | + */ | |
| 112 | +	public function add_template_path( $file_paths ) { | |
| 113 | + | |
| 114 | + // Index 100 is the default GravityView template path. | |
| 115 | + $file_paths[ 110 ] = self::$file; | |
| 116 | + | |
| 117 | + return $file_paths; | |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * | |
| 122 | + * Return a well formatted nonce key according to GravityView Edit Entry protocol | |
| 123 | + * | |
| 124 | + * @param $view_id int GravityView view id | |
| 125 | + * @param $form_id int Gravity Forms form id | |
| 126 | + * @param $entry_id int Gravity Forms entry id | |
| 127 | + * @return string | |
| 128 | + */ | |
| 129 | +	public static function get_nonce_key( $view_id, $form_id, $entry_id ) { | |
| 130 | + return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); | |
| 131 | + } | |
| 132 | + | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * The edit entry link creates a secure link with a nonce | |
| 136 | + * | |
| 137 | + * It also mimics the URL structure Gravity Forms expects to have so that | |
| 138 | + * it formats the display of the edit form like it does in the backend, like | |
| 139 | + * "You can edit this post from the post page" fields, for example. | |
| 140 | + * | |
| 141 | + * @param $entry array Gravity Forms entry object | |
| 142 | + * @param $view_id int GravityView view id | |
| 143 | +	 * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} | |
| 144 | +	 * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } | |
| 145 | + * @return string | |
| 146 | + */ | |
| 147 | +	public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { | |
| 148 | + | |
| 149 | + $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); | |
| 150 | + | |
| 151 | + $base = gv_entry_link( $entry, $post_id ); | |
| 152 | + | |
| 153 | + $url = add_query_arg( array( | |
| 154 | + 'page' => 'gf_entries', // Needed for GFForms::get_page() | |
| 155 | + 'view' => 'entry', // Needed for GFForms::get_page() | |
| 156 | + 'edit' => wp_create_nonce( $nonce_key ) | |
| 157 | + ), $base ); | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * Allow passing params to dynamically populate entry with values | |
| 161 | + * @since 1.9.2 | |
| 162 | + */ | |
| 163 | +		if( !empty( $field_values ) ) { | |
| 164 | + | |
| 165 | +			if( is_array( $field_values ) ) { | |
| 166 | + // If already an array, no parse_str() needed | |
| 167 | + $params = $field_values; | |
| 168 | +			} else { | |
| 169 | + parse_str( $field_values, $params ); | |
| 170 | + } | |
| 171 | + | |
| 172 | + $url = add_query_arg( $params, $url ); | |
| 173 | + } | |
| 174 | + | |
| 175 | + return $url; | |
| 176 | + } | |
| 177 | 177 | |
| 178 | 178 | |
| 179 | 179 | /** | 
| @@ -209,81 +209,81 @@ discard block | ||
| 209 | 209 | } | 
| 210 | 210 | |
| 211 | 211 | |
| 212 | - /** | |
| 213 | - * checks if user has permissions to edit a specific entry | |
| 214 | - * | |
| 215 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! | |
| 216 | - * | |
| 217 | - * @param array $entry Gravity Forms entry array | |
| 218 | -     * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2} | |
| 219 | - * @return bool | |
| 220 | - */ | |
| 221 | -    public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { | |
| 212 | + /** | |
| 213 | + * checks if user has permissions to edit a specific entry | |
| 214 | + * | |
| 215 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! | |
| 216 | + * | |
| 217 | + * @param array $entry Gravity Forms entry array | |
| 218 | +	 * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2} | |
| 219 | + * @return bool | |
| 220 | + */ | |
| 221 | +	public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { | |
| 222 | 222 | |
| 223 | - // No permission by default | |
| 224 | - $user_can_edit = false; | |
| 223 | + // No permission by default | |
| 224 | + $user_can_edit = false; | |
| 225 | 225 | |
| 226 | - // If they can edit any entries (as defined in Gravity Forms) | |
| 227 | - // Or if they can edit other people's entries | |
| 228 | - // Then we're good. | |
| 229 | -        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { | |
| 226 | + // If they can edit any entries (as defined in Gravity Forms) | |
| 227 | + // Or if they can edit other people's entries | |
| 228 | + // Then we're good. | |
| 229 | +		if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { | |
| 230 | 230 | |
| 231 | -            do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.'); | |
| 231 | +			do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.'); | |
| 232 | 232 | |
| 233 | - $user_can_edit = true; | |
| 233 | + $user_can_edit = true; | |
| 234 | 234 | |
| 235 | -        } else if( !isset( $entry['created_by'] ) ) { | |
| 235 | +		} else if( !isset( $entry['created_by'] ) ) { | |
| 236 | 236 | |
| 237 | -            do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.'); | |
| 237 | +			do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.'); | |
| 238 | 238 | |
| 239 | - $user_can_edit = false; | |
| 239 | + $user_can_edit = false; | |
| 240 | 240 | |
| 241 | -        } else { | |
| 241 | +		} else { | |
| 242 | 242 | |
| 243 | - // get user_edit setting | |
| 244 | -            if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { | |
| 245 | - // if View ID not specified or is the current view | |
| 246 | -                $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); | |
| 247 | -            } else { | |
| 248 | - // in case is specified and not the current view | |
| 249 | - $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); | |
| 250 | - } | |
| 243 | + // get user_edit setting | |
| 244 | +			if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { | |
| 245 | + // if View ID not specified or is the current view | |
| 246 | +				$user_edit = GravityView_View::getInstance()->getAtts('user_edit'); | |
| 247 | +			} else { | |
| 248 | + // in case is specified and not the current view | |
| 249 | + $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); | |
| 250 | + } | |
| 251 | 251 | |
| 252 | - $current_user = wp_get_current_user(); | |
| 252 | + $current_user = wp_get_current_user(); | |
| 253 | 253 | |
| 254 | - // User edit is disabled | |
| 255 | -            if( empty( $user_edit ) ) { | |
| 254 | + // User edit is disabled | |
| 255 | +			if( empty( $user_edit ) ) { | |
| 256 | 256 | |
| 257 | -                do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); | |
| 257 | +				do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); | |
| 258 | 258 | |
| 259 | - $user_can_edit = false; | |
| 260 | - } | |
| 259 | + $user_can_edit = false; | |
| 260 | + } | |
| 261 | 261 | |
| 262 | - // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. | |
| 263 | -            else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { | |
| 262 | + // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. | |
| 263 | +			else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { | |
| 264 | 264 | |
| 265 | -                do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); | |
| 265 | +				do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); | |
| 266 | 266 | |
| 267 | - $user_can_edit = true; | |
| 267 | + $user_can_edit = true; | |
| 268 | 268 | |
| 269 | -            } else if( ! is_user_logged_in() ) { | |
| 269 | +			} else if( ! is_user_logged_in() ) { | |
| 270 | 270 | |
| 271 | - do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' ); | |
| 272 | - } | |
| 271 | + do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' ); | |
| 272 | + } | |
| 273 | 273 | |
| 274 | - } | |
| 274 | + } | |
| 275 | 275 | |
| 276 | - /** | |
| 277 | - * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. | |
| 278 | - * @since 1.15 Added `$entry` and `$view_id` parameters | |
| 279 | - * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) | |
| 280 | -         * @param[in] array $entry Gravity Forms entry array {@since 1.15} | |
| 281 | -         * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} | |
| 282 | - */ | |
| 283 | - $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); | |
| 276 | + /** | |
| 277 | + * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. | |
| 278 | + * @since 1.15 Added `$entry` and `$view_id` parameters | |
| 279 | + * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) | |
| 280 | +		 * @param[in] array $entry Gravity Forms entry array {@since 1.15} | |
| 281 | +		 * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} | |
| 282 | + */ | |
| 283 | + $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); | |
| 284 | 284 | |
| 285 | - return (bool)$user_can_edit; | |
| 286 | - } | |
| 285 | + return (bool)$user_can_edit; | |
| 286 | + } | |
| 287 | 287 | |
| 288 | 288 | |
| 289 | 289 | |
| @@ -36,7 +36,7 @@ discard block | ||
| 36 | 36 | |
| 37 | 37 | self::$file = plugin_dir_path( __FILE__ ); | 
| 38 | 38 | |
| 39 | -        if( is_admin() ) { | |
| 39 | +        if ( is_admin() ) { | |
| 40 | 40 | $this->load_components( 'admin' ); | 
| 41 | 41 | } | 
| 42 | 42 | |
| @@ -55,7 +55,7 @@ discard block | ||
| 55 | 55 | |
| 56 | 56 |      static function getInstance() { | 
| 57 | 57 | |
| 58 | -        if( empty( self::$instance ) ) { | |
| 58 | +        if ( empty( self::$instance ) ) { | |
| 59 | 59 | self::$instance = new GravityView_Edit_Entry; | 
| 60 | 60 | } | 
| 61 | 61 | |
| @@ -81,10 +81,10 @@ discard block | ||
| 81 | 81 |      private function add_hooks() { | 
| 82 | 82 | |
| 83 | 83 | // Add front-end access to Gravity Forms delete file action | 
| 84 | - add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file') ); | |
| 84 | + add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file' ) ); | |
| 85 | 85 | |
| 86 | 86 | // Make sure this hook is run for non-admins | 
| 87 | - add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file') ); | |
| 87 | + add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file' ) ); | |
| 88 | 88 | |
| 89 | 89 | add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); | 
| 90 | 90 | |
| @@ -99,8 +99,8 @@ discard block | ||
| 99 | 99 | */ | 
| 100 | 100 |  	private function addon_specific_hooks() { | 
| 101 | 101 | |
| 102 | -		if( class_exists( 'GFSignature' ) && is_callable( array( 'GFSignature', 'get_instance' ) ) ) { | |
| 103 | -			add_filter('gform_admin_pre_render', array( GFSignature::get_instance(), 'edit_lead_script')); | |
| 102 | +		if ( class_exists( 'GFSignature' ) && is_callable( array( 'GFSignature', 'get_instance' ) ) ) { | |
| 103 | + add_filter( 'gform_admin_pre_render', array( GFSignature::get_instance(), 'edit_lead_script' ) ); | |
| 104 | 104 | } | 
| 105 | 105 | |
| 106 | 106 | } | 
| @@ -146,7 +146,7 @@ discard block | ||
| 146 | 146 | */ | 
| 147 | 147 |      public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { | 
| 148 | 148 | |
| 149 | - $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); | |
| 149 | + $nonce_key = self::get_nonce_key( $view_id, $entry[ 'form_id' ], $entry[ 'id' ] ); | |
| 150 | 150 | |
| 151 | 151 | $base = gv_entry_link( $entry, $post_id ); | 
| 152 | 152 | |
| @@ -160,9 +160,9 @@ discard block | ||
| 160 | 160 | * Allow passing params to dynamically populate entry with values | 
| 161 | 161 | * @since 1.9.2 | 
| 162 | 162 | */ | 
| 163 | -	    if( !empty( $field_values ) ) { | |
| 163 | +	    if ( ! empty( $field_values ) ) { | |
| 164 | 164 | |
| 165 | -		    if( is_array( $field_values ) ) { | |
| 165 | +		    if ( is_array( $field_values ) ) { | |
| 166 | 166 | // If already an array, no parse_str() needed | 
| 167 | 167 | $params = $field_values; | 
| 168 | 168 |  		    } else { | 
| @@ -184,7 +184,7 @@ discard block | ||
| 184 | 184 | */ | 
| 185 | 185 |  	public function modify_field_blacklist( $fields = array(), $context = NULL ) { | 
| 186 | 186 | |
| 187 | -		if( empty( $context ) || $context !== 'edit' ) { | |
| 187 | +		if ( empty( $context ) || $context !== 'edit' ) { | |
| 188 | 188 | return $fields; | 
| 189 | 189 | } | 
| 190 | 190 | |
| @@ -226,24 +226,24 @@ discard block | ||
| 226 | 226 | // If they can edit any entries (as defined in Gravity Forms) | 
| 227 | 227 | // Or if they can edit other people's entries | 
| 228 | 228 | // Then we're good. | 
| 229 | -        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { | |
| 229 | +        if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry[ 'id' ] ) ) { | |
| 230 | 230 | |
| 231 | -            do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.'); | |
| 231 | + do_action( 'gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.' ); | |
| 232 | 232 | |
| 233 | 233 | $user_can_edit = true; | 
| 234 | 234 | |
| 235 | -        } else if( !isset( $entry['created_by'] ) ) { | |
| 235 | +        } else if ( ! isset( $entry[ 'created_by' ] ) ) { | |
| 236 | 236 | |
| 237 | -            do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.'); | |
| 237 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.' ); | |
| 238 | 238 | |
| 239 | 239 | $user_can_edit = false; | 
| 240 | 240 | |
| 241 | 241 |          } else { | 
| 242 | 242 | |
| 243 | 243 | // get user_edit setting | 
| 244 | -            if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { | |
| 244 | +            if ( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { | |
| 245 | 245 | // if View ID not specified or is the current view | 
| 246 | -                $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); | |
| 246 | + $user_edit = GravityView_View::getInstance()->getAtts( 'user_edit' ); | |
| 247 | 247 |              } else { | 
| 248 | 248 | // in case is specified and not the current view | 
| 249 | 249 | $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); | 
| @@ -252,21 +252,21 @@ discard block | ||
| 252 | 252 | $current_user = wp_get_current_user(); | 
| 253 | 253 | |
| 254 | 254 | // User edit is disabled | 
| 255 | -            if( empty( $user_edit ) ) { | |
| 255 | +            if ( empty( $user_edit ) ) { | |
| 256 | 256 | |
| 257 | -                do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); | |
| 257 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); | |
| 258 | 258 | |
| 259 | 259 | $user_can_edit = false; | 
| 260 | 260 | } | 
| 261 | 261 | |
| 262 | 262 | // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. | 
| 263 | -            else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { | |
| 263 | +            else if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) { | |
| 264 | 264 | |
| 265 | -                do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); | |
| 265 | + do_action( 'gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); | |
| 266 | 266 | |
| 267 | 267 | $user_can_edit = true; | 
| 268 | 268 | |
| 269 | -            } else if( ! is_user_logged_in() ) { | |
| 269 | +            } else if ( ! is_user_logged_in() ) { | |
| 270 | 270 | |
| 271 | 271 | do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' ); | 
| 272 | 272 | } | 
| @@ -102,16 +102,16 @@ discard block | ||
| 102 | 102 |      function load() { | 
| 103 | 103 | |
| 104 | 104 | /** @define "GRAVITYVIEW_DIR" "../../../" */ | 
| 105 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); | |
| 105 | + include_once( GRAVITYVIEW_DIR . 'includes/class-admin-approve-entries.php' ); | |
| 106 | 106 | |
| 107 | 107 | // Don't display an embedded form when editing an entry | 
| 108 | 108 | add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); | 
| 109 | 109 | add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); | 
| 110 | 110 | |
| 111 | 111 | // Stop Gravity Forms processing what is ours! | 
| 112 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); | |
| 112 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form' ), 8 ); | |
| 113 | 113 | |
| 114 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); | |
| 114 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry' ) ); | |
| 115 | 115 | |
| 116 | 116 | add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); | 
| 117 | 117 | |
| @@ -122,7 +122,7 @@ discard block | ||
| 122 | 122 | add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); | 
| 123 | 123 | |
| 124 | 124 | // Add fields expected by GFFormDisplay::validate() | 
| 125 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); | |
| 125 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation' ) ); | |
| 126 | 126 | |
| 127 | 127 | } | 
| 128 | 128 | |
| @@ -137,8 +137,8 @@ discard block | ||
| 137 | 137 | * @return void | 
| 138 | 138 | */ | 
| 139 | 139 |      function prevent_render_form() { | 
| 140 | -        if( $this->is_edit_entry() ) { | |
| 141 | -            if( 'wp_head' === current_filter() ) { | |
| 140 | +        if ( $this->is_edit_entry() ) { | |
| 141 | +            if ( 'wp_head' === current_filter() ) { | |
| 142 | 142 | add_filter( 'gform_shortcode_form', '__return_empty_string' ); | 
| 143 | 143 |              } else { | 
| 144 | 144 | remove_filter( 'gform_shortcode_form', '__return_empty_string' ); | 
| @@ -153,10 +153,10 @@ discard block | ||
| 153 | 153 | */ | 
| 154 | 154 |      function prevent_maybe_process_form() { | 
| 155 | 155 | |
| 156 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 156 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 157 | 157 | |
| 158 | -        if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { | |
| 159 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); | |
| 158 | +        if ( $this->is_edit_entry_submission() && $this->verify_nonce() ) { | |
| 159 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form' ), 9 ); | |
| 160 | 160 | } | 
| 161 | 161 | } | 
| 162 | 162 | |
| @@ -168,7 +168,7 @@ discard block | ||
| 168 | 168 | |
| 169 | 169 | $gf_page = ( 'entry' === RGForms::get( 'view' ) ); | 
| 170 | 170 | |
| 171 | - return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); | |
| 171 | + return ( $gf_page && isset( $_GET[ 'edit' ] ) || RGForms::post( 'action' ) === 'update' ); | |
| 172 | 172 | } | 
| 173 | 173 | |
| 174 | 174 | /** | 
| @@ -177,7 +177,7 @@ discard block | ||
| 177 | 177 | * @return boolean | 
| 178 | 178 | */ | 
| 179 | 179 |  	public function is_edit_entry_submission() { | 
| 180 | - return !empty( $_POST[ self::$nonce_field ] ); | |
| 180 | + return ! empty( $_POST[ self::$nonce_field ] ); | |
| 181 | 181 | } | 
| 182 | 182 | |
| 183 | 183 | /** | 
| @@ -188,13 +188,13 @@ discard block | ||
| 188 | 188 | |
| 189 | 189 | |
| 190 | 190 | $entries = $gravityview_view->getEntries(); | 
| 191 | - $this->entry = $entries[0]; | |
| 191 | + $this->entry = $entries[ 0 ]; | |
| 192 | 192 | |
| 193 | 193 | $this->original_form = $this->form = $gravityview_view->getForm(); | 
| 194 | 194 | $this->form_id = $gravityview_view->getFormId(); | 
| 195 | 195 | $this->view_id = $gravityview_view->getViewId(); | 
| 196 | 196 | |
| 197 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); | |
| 197 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry[ 'id' ] ); | |
| 198 | 198 | } | 
| 199 | 199 | |
| 200 | 200 | |
| @@ -214,12 +214,12 @@ discard block | ||
| 214 | 214 | $this->setup_vars(); | 
| 215 | 215 | |
| 216 | 216 | // Multiple Views embedded, don't proceed if nonce fails | 
| 217 | -        if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { | |
| 217 | +        if ( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ) ) { | |
| 218 | 218 | return; | 
| 219 | 219 | } | 
| 220 | 220 | |
| 221 | 221 | // Sorry, you're not allowed here. | 
| 222 | -        if( false === $this->user_can_edit_entry( true ) ) { | |
| 222 | +        if ( false === $this->user_can_edit_entry( true ) ) { | |
| 223 | 223 | return; | 
| 224 | 224 | } | 
| 225 | 225 | |
| @@ -239,9 +239,9 @@ discard block | ||
| 239 | 239 |      function print_scripts() { | 
| 240 | 240 | $gravityview_view = GravityView_View::getInstance(); | 
| 241 | 241 | |
| 242 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); | |
| 242 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url() . '/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); | |
| 243 | 243 | |
| 244 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); | |
| 244 | + GFFormDisplay::enqueue_form_scripts( $gravityview_view->getForm(), false ); | |
| 245 | 245 | |
| 246 | 246 | // Sack is required for images | 
| 247 | 247 | wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); | 
| @@ -253,32 +253,32 @@ discard block | ||
| 253 | 253 | */ | 
| 254 | 254 |      function process_save() { | 
| 255 | 255 | |
| 256 | -        if( empty( $_POST ) ) { | |
| 256 | +        if ( empty( $_POST ) ) { | |
| 257 | 257 | return; | 
| 258 | 258 | } | 
| 259 | 259 | |
| 260 | 260 | // Make sure the entry, view, and form IDs are all correct | 
| 261 | 261 | $valid = $this->verify_nonce(); | 
| 262 | 262 | |
| 263 | -        if( !$valid ) { | |
| 264 | -            do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); | |
| 263 | +        if ( ! $valid ) { | |
| 264 | + do_action( 'gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); | |
| 265 | 265 | return; | 
| 266 | 266 | } | 
| 267 | 267 | |
| 268 | -        if( $this->entry['id'] !== $_POST['lid'] ) { | |
| 269 | -            do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); | |
| 268 | +        if ( $this->entry[ 'id' ] !== $_POST[ 'lid' ] ) { | |
| 269 | + do_action( 'gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); | |
| 270 | 270 | return; | 
| 271 | 271 | } | 
| 272 | 272 | |
| 273 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 273 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 274 | 274 | |
| 275 | 275 | $this->process_save_process_files( $this->form_id ); | 
| 276 | 276 | |
| 277 | 277 | $this->validate(); | 
| 278 | 278 | |
| 279 | -        if( $this->is_valid ) { | |
| 279 | +        if ( $this->is_valid ) { | |
| 280 | 280 | |
| 281 | -            do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); | |
| 281 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); | |
| 282 | 282 | |
| 283 | 283 | /** | 
| 284 | 284 | * @hack This step is needed to unset the adminOnly from form fields | 
| @@ -288,12 +288,12 @@ discard block | ||
| 288 | 288 | /** | 
| 289 | 289 | * @hack to avoid the capability validation of the method save_lead for GF 1.9+ | 
| 290 | 290 | */ | 
| 291 | - unset( $_GET['page'] ); | |
| 291 | + unset( $_GET[ 'page' ] ); | |
| 292 | 292 | |
| 293 | 293 | GFFormsModel::save_lead( $form, $this->entry ); | 
| 294 | 294 | |
| 295 | 295 | // If there's a post associated with the entry, process post fields | 
| 296 | -            if( !empty( $this->entry['post_id'] ) ) { | |
| 296 | +            if ( ! empty( $this->entry[ 'post_id' ] ) ) { | |
| 297 | 297 | $this->maybe_update_post_fields( $form ); | 
| 298 | 298 | } | 
| 299 | 299 | |
| @@ -305,7 +305,7 @@ discard block | ||
| 305 | 305 | * @param array $form Gravity Forms form array | 
| 306 | 306 | * @param string $entry_id Numeric ID of the entry that was updated | 
| 307 | 307 | */ | 
| 308 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); | |
| 308 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry[ 'id' ] ); | |
| 309 | 309 | } | 
| 310 | 310 | |
| 311 | 311 | } // process_save | 
| @@ -339,11 +339,11 @@ discard block | ||
| 339 | 339 | * @return mixed | 
| 340 | 340 | */ | 
| 341 | 341 |      public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { | 
| 342 | -        if( ! $this->is_edit_entry() ) { | |
| 342 | +        if ( ! $this->is_edit_entry() ) { | |
| 343 | 343 | return $plupload_init; | 
| 344 | 344 | } | 
| 345 | 345 | |
| 346 | - $plupload_init['gf_vars']['max_files'] = 0; | |
| 346 | + $plupload_init[ 'gf_vars' ][ 'max_files' ] = 0; | |
| 347 | 347 | |
| 348 | 348 | return $plupload_init; | 
| 349 | 349 | } | 
| @@ -356,13 +356,13 @@ discard block | ||
| 356 | 356 |      private function form_prepare_for_save() { | 
| 357 | 357 | $form = $this->original_form; | 
| 358 | 358 | |
| 359 | -        foreach( $form['fields'] as &$field ) { | |
| 359 | +        foreach ( $form[ 'fields' ] as &$field ) { | |
| 360 | 360 | |
| 361 | 361 | $field->adminOnly = false; | 
| 362 | 362 | |
| 363 | -            if( isset( $field->inputs ) && is_array( $field->inputs ) ) { | |
| 364 | -                foreach( $field->inputs as $key => $input ) { | |
| 365 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; | |
| 363 | +            if ( isset( $field->inputs ) && is_array( $field->inputs ) ) { | |
| 364 | +                foreach ( $field->inputs as $key => $input ) { | |
| 365 | + $field->inputs[ $key ][ 'id' ] = (string)$input[ 'id' ]; | |
| 366 | 366 | } | 
| 367 | 367 | } | 
| 368 | 368 | } | 
| @@ -380,11 +380,11 @@ discard block | ||
| 380 | 380 | */ | 
| 381 | 381 |      function maybe_update_post_fields( $form ) { | 
| 382 | 382 | |
| 383 | - $post_id = $this->entry['post_id']; | |
| 383 | + $post_id = $this->entry[ 'post_id' ]; | |
| 384 | 384 | |
| 385 | 385 | // Security check | 
| 386 | -        if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { | |
| 387 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); | |
| 386 | +        if ( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { | |
| 387 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id ); | |
| 388 | 388 | return; | 
| 389 | 389 | } | 
| 390 | 390 | |
| @@ -398,16 +398,16 @@ discard block | ||
| 398 | 398 | |
| 399 | 399 | $field = RGFormsModel::get_field( $form, $field_id ); | 
| 400 | 400 | |
| 401 | -            if( class_exists('GF_Fields') ) { | |
| 401 | +            if ( class_exists( 'GF_Fields' ) ) { | |
| 402 | 402 | $field = GF_Fields::create( $field ); | 
| 403 | 403 | } | 
| 404 | 404 | |
| 405 | -            if( GFCommon::is_post_field( $field ) ) { | |
| 405 | +            if ( GFCommon::is_post_field( $field ) ) { | |
| 406 | 406 | |
| 407 | 407 | // Get the value of the field, including $_POSTed value | 
| 408 | 408 | $value = RGFormsModel::get_field_value( $field ); | 
| 409 | 409 | |
| 410 | -                switch( $field->type ) { | |
| 410 | +                switch ( $field->type ) { | |
| 411 | 411 | |
| 412 | 412 | case 'post_title': | 
| 413 | 413 | case 'post_content': | 
| @@ -425,14 +425,14 @@ discard block | ||
| 425 | 425 | wp_set_post_categories( $post_id, $categories, false ); | 
| 426 | 426 | |
| 427 | 427 | // if post_category is type checkbox, then value is an array of inputs | 
| 428 | -                        if( isset( $value[ strval( $field_id ) ] ) ) { | |
| 429 | -                            foreach( $value as $input_id => $val ) { | |
| 428 | +                        if ( isset( $value[ strval( $field_id ) ] ) ) { | |
| 429 | +                            foreach ( $value as $input_id => $val ) { | |
| 430 | 430 | $input_name = 'input_' . str_replace( '.', '_', $input_id ); | 
| 431 | - $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); | |
| 431 | + $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry[ 'id' ] ); | |
| 432 | 432 | } | 
| 433 | 433 |                          } else { | 
| 434 | 434 | $input_name = 'input_' . str_replace( '.', '_', $field_id ); | 
| 435 | - $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); | |
| 435 | + $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry[ 'id' ] ); | |
| 436 | 436 | } | 
| 437 | 437 | |
| 438 | 438 | break; | 
| @@ -442,12 +442,12 @@ discard block | ||
| 442 | 442 | $custom_field_name = $field->postCustomFieldName; | 
| 443 | 443 | |
| 444 | 444 | // Only certain custom field types are supported | 
| 445 | -                        switch( $input_type ) { | |
| 445 | +                        switch ( $input_type ) { | |
| 446 | 446 | case 'fileupload': | 
| 447 | 447 | /** @noinspection PhpMissingBreakStatementInspection */ | 
| 448 | 448 | case 'list': | 
| 449 | -                                if( ! is_string( $value ) ) { | |
| 450 | -                                    $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); | |
| 449 | +                                if ( ! is_string( $value ) ) { | |
| 450 | + $value = function_exists( 'wp_json_encode' ) ? wp_json_encode( $value ) : json_encode( $value ); | |
| 451 | 451 | } | 
| 452 | 452 | // break; left intentionally out | 
| 453 | 453 | default: | 
| @@ -460,11 +460,11 @@ discard block | ||
| 460 | 460 | |
| 461 | 461 | $input_name = 'input_' . $field_id; | 
| 462 | 462 | |
| 463 | -                        if ( !empty( $_FILES[ $input_name ]['name'] ) ) { | |
| 463 | +                        if ( ! empty( $_FILES[ $input_name ][ 'name' ] ) ) { | |
| 464 | 464 | |
| 465 | 465 | // We have a new image | 
| 466 | 466 | |
| 467 | - $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); | |
| 467 | + $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry[ 'id' ] ); | |
| 468 | 468 | |
| 469 | 469 | // is this field set as featured image, if not, leave | 
| 470 | 470 |                              if ( ! $field->postFeaturedImage ) { | 
| @@ -474,9 +474,9 @@ discard block | ||
| 474 | 474 | $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); | 
| 475 | 475 | $img_url = rgar( $ary, 0 ); | 
| 476 | 476 | |
| 477 | - $img_title = count( $ary ) > 1 ? $ary[1] : ''; | |
| 478 | - $img_caption = count( $ary ) > 2 ? $ary[2] : ''; | |
| 479 | - $img_description = count( $ary ) > 3 ? $ary[3] : ''; | |
| 477 | + $img_title = count( $ary ) > 1 ? $ary[ 1 ] : ''; | |
| 478 | + $img_caption = count( $ary ) > 2 ? $ary[ 2 ] : ''; | |
| 479 | + $img_description = count( $ary ) > 3 ? $ary[ 3 ] : ''; | |
| 480 | 480 | |
| 481 | 481 | $image_meta = array( | 
| 482 | 482 | 'post_excerpt' => $img_caption, | 
| @@ -485,7 +485,7 @@ discard block | ||
| 485 | 485 | |
| 486 | 486 | //adding title only if it is not empty. It will default to the file name if it is not in the array | 
| 487 | 487 |                              if ( ! empty( $img_title ) ) { | 
| 488 | - $image_meta['post_title'] = $img_title; | |
| 488 | + $image_meta[ 'post_title' ] = $img_title; | |
| 489 | 489 | } | 
| 490 | 490 | |
| 491 | 491 | //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. | 
| @@ -498,7 +498,7 @@ discard block | ||
| 498 | 498 | |
| 499 | 499 | break; | 
| 500 | 500 | |
| 501 | -                        } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { | |
| 501 | +                        } elseif ( ! empty( $_POST[ $input_name ] ) && is_array( $value ) ) { | |
| 502 | 502 | |
| 503 | 503 | // Same image although the image title, caption or description might have changed | 
| 504 | 504 | |
| @@ -506,11 +506,11 @@ discard block | ||
| 506 | 506 | $img_url = rgar( $ary, 0 ); | 
| 507 | 507 | |
| 508 | 508 | // is this really the same image or something went wrong ? | 
| 509 | -                            if( $img_url === $_POST[ $input_name ] ) { | |
| 509 | +                            if ( $img_url === $_POST[ $input_name ] ) { | |
| 510 | 510 | |
| 511 | - $img_title = isset( $value[ $field_id .'.1' ] ) ? $value[ $field_id .'.1' ] : ''; | |
| 512 | - $img_caption = isset( $value[ $field_id .'.4' ] ) ? $value[ $field_id .'.4' ] : ''; | |
| 513 | - $img_description = isset( $value[ $field_id .'.7' ] ) ? $value[ $field_id .'.7' ] : ''; | |
| 511 | + $img_title = isset( $value[ $field_id . '.1' ] ) ? $value[ $field_id . '.1' ] : ''; | |
| 512 | + $img_caption = isset( $value[ $field_id . '.4' ] ) ? $value[ $field_id . '.4' ] : ''; | |
| 513 | + $img_description = isset( $value[ $field_id . '.7' ] ) ? $value[ $field_id . '.7' ] : ''; | |
| 514 | 514 | |
| 515 | 515 | $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; | 
| 516 | 516 | |
| @@ -544,12 +544,12 @@ discard block | ||
| 544 | 544 | } | 
| 545 | 545 | |
| 546 | 546 | //ignore fields that have not changed | 
| 547 | -                if ( $value === rgget( (string) $field_id, $this->entry ) ) { | |
| 547 | +                if ( $value === rgget( (string)$field_id, $this->entry ) ) { | |
| 548 | 548 | continue; | 
| 549 | 549 | } | 
| 550 | 550 | |
| 551 | 551 | // update entry | 
| 552 | -                if( 'post_category' !== $field->type ) { | |
| 552 | +                if ( 'post_category' !== $field->type ) { | |
| 553 | 553 | $this->entry[ strval( $field_id ) ] = $value; | 
| 554 | 554 | } | 
| 555 | 555 | |
| @@ -559,25 +559,25 @@ discard block | ||
| 559 | 559 | |
| 560 | 560 | } | 
| 561 | 561 | |
| 562 | -        if( $update_entry ) { | |
| 562 | +        if ( $update_entry ) { | |
| 563 | 563 | |
| 564 | 564 | $return_entry = GFAPI::update_entry( $this->entry ); | 
| 565 | 565 | |
| 566 | -            if( is_wp_error( $return_entry ) ) { | |
| 566 | +            if ( is_wp_error( $return_entry ) ) { | |
| 567 | 567 | do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); | 
| 568 | 568 |              } else { | 
| 569 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); | |
| 569 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded' ); | |
| 570 | 570 | } | 
| 571 | 571 | |
| 572 | 572 | } | 
| 573 | 573 | |
| 574 | 574 | $return_post = wp_update_post( $updated_post, true ); | 
| 575 | 575 | |
| 576 | -        if( is_wp_error( $return_post ) ) { | |
| 576 | +        if ( is_wp_error( $return_post ) ) { | |
| 577 | 577 | $return_post->add_data( $updated_post, '$updated_post' ); | 
| 578 | 578 | do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); | 
| 579 | 579 |          } else { | 
| 580 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); | |
| 580 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded', $updated_post ); | |
| 581 | 581 | } | 
| 582 | 582 | |
| 583 | 583 | } | 
| @@ -594,18 +594,18 @@ discard block | ||
| 594 | 594 | */ | 
| 595 | 595 |      function after_update() { | 
| 596 | 596 | |
| 597 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); | |
| 598 | -        do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); | |
| 597 | + do_action( 'gform_after_update_entry', $this->form, $this->entry[ 'id' ] ); | |
| 598 | +        do_action( "gform_after_update_entry_{$this->form[ 'id' ]}", $this->form, $this->entry[ 'id' ] ); | |
| 599 | 599 | |
| 600 | 600 | // Re-define the entry now that we've updated it. | 
| 601 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); | |
| 601 | + $entry = RGFormsModel::get_lead( $this->entry[ 'id' ] ); | |
| 602 | 602 | |
| 603 | 603 | $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); | 
| 604 | 604 | |
| 605 | 605 | // We need to clear the cache because Gravity Forms caches the field values, which | 
| 606 | 606 | // we have just updated. | 
| 607 | -        foreach ($this->form['fields'] as $key => $field) { | |
| 608 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); | |
| 607 | +        foreach ( $this->form[ 'fields' ] as $key => $field ) { | |
| 608 | + GFFormsModel::refresh_lead_field_value( $entry[ 'id' ], $field->id ); | |
| 609 | 609 | } | 
| 610 | 610 | |
| 611 | 611 | $this->entry = $entry; | 
| @@ -623,7 +623,7 @@ discard block | ||
| 623 | 623 | |
| 624 | 624 | <div class="gv-edit-entry-wrapper"><?php | 
| 625 | 625 | |
| 626 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); | |
| 626 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/inline-javascript.php', $this ); | |
| 627 | 627 | |
| 628 | 628 | /** | 
| 629 | 629 | * Fixes weird wpautop() issue | 
| @@ -639,7 +639,7 @@ discard block | ||
| 639 | 639 | * @param string $edit_entry_title Modify the "Edit Entry" title | 
| 640 | 640 | * @param GravityView_Edit_Entry_Render $this This object | 
| 641 | 641 | */ | 
| 642 | -                    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); | |
| 642 | + $edit_entry_title = apply_filters( 'gravityview_edit_entry_title', __( 'Edit Entry', 'gravityview' ), $this ); | |
| 643 | 643 | |
| 644 | 644 | echo esc_attr( $edit_entry_title ); | 
| 645 | 645 | ?></span> | 
| @@ -679,20 +679,20 @@ discard block | ||
| 679 | 679 | */ | 
| 680 | 680 |      private function maybe_print_message() { | 
| 681 | 681 | |
| 682 | -        if( rgpost('action') === 'update' ) { | |
| 682 | +        if ( rgpost( 'action' ) === 'update' ) { | |
| 683 | 683 | |
| 684 | 684 | $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); | 
| 685 | 685 | |
| 686 | -            if( ! $this->is_valid ){ | |
| 686 | +            if ( ! $this->is_valid ) { | |
| 687 | 687 | |
| 688 | 688 | // Keeping this compatible with Gravity Forms. | 
| 689 | -                $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; | |
| 690 | -                $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); | |
| 689 | + $validation_message = "<div class='validation_error'>" . __( 'There was a problem with your submission.', 'gravityview' ) . " " . __( 'Errors have been highlighted below.', 'gravityview' ) . "</div>"; | |
| 690 | +                $message = apply_filters( "gform_validation_message_{$this->form[ 'id' ]}", apply_filters( "gform_validation_message", $validation_message, $this->form ), $this->form ); | |
| 691 | 691 | |
| 692 | - echo GVCommon::generate_notice( $message , 'gv-error' ); | |
| 692 | + echo GVCommon::generate_notice( $message, 'gv-error' ); | |
| 693 | 693 | |
| 694 | 694 |              } else { | 
| 695 | -                $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); | |
| 695 | + $entry_updated_message = sprintf( esc_attr__( 'Entry Updated. %sReturn to Entry%s', 'gravityview' ), '<a href="' . $back_link . '">', '</a>' ); | |
| 696 | 696 | |
| 697 | 697 | /** | 
| 698 | 698 | * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) | 
| @@ -702,7 +702,7 @@ discard block | ||
| 702 | 702 | * @param array $entry Gravity Forms entry array | 
| 703 | 703 | * @param string $back_link URL to return to the original entry. @since 1.6 | 
| 704 | 704 | */ | 
| 705 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); | |
| 705 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry, $back_link ); | |
| 706 | 706 | |
| 707 | 707 | echo GVCommon::generate_notice( $message ); | 
| 708 | 708 | } | 
| @@ -723,15 +723,15 @@ discard block | ||
| 723 | 723 | */ | 
| 724 | 724 |      private function render_edit_form() { | 
| 725 | 725 | |
| 726 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); | |
| 727 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); | |
| 726 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000, 3 ); | |
| 727 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); | |
| 728 | 728 | add_filter( 'gform_disable_view_counter', '__return_true' ); | 
| 729 | 729 | |
| 730 | 730 | add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); | 
| 731 | 731 | add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); | 
| 732 | 732 | |
| 733 | 733 | // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. | 
| 734 | - unset( $_GET['page'] ); | |
| 734 | + unset( $_GET[ 'page' ] ); | |
| 735 | 735 | |
| 736 | 736 | // TODO: Make sure validation isn't handled by GF | 
| 737 | 737 | // TODO: Include CSS for file upload fields | 
| @@ -739,7 +739,7 @@ discard block | ||
| 739 | 739 | // TODO: Product fields are not editable | 
| 740 | 740 | // TODO: Check Updated and Error messages | 
| 741 | 741 | |
| 742 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); | |
| 742 | + $html = GFFormDisplay::get_form( $this->form[ 'id' ], false, false, true, $this->entry ); | |
| 743 | 743 | |
| 744 | 744 | remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); | 
| 745 | 745 | remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); | 
| @@ -756,7 +756,7 @@ discard block | ||
| 756 | 756 | * @return string | 
| 757 | 757 | */ | 
| 758 | 758 |      public function render_form_buttons() { | 
| 759 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); | |
| 759 | + return gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/form-buttons.php', $this ); | |
| 760 | 760 | } | 
| 761 | 761 | |
| 762 | 762 | |
| @@ -776,17 +776,17 @@ discard block | ||
| 776 | 776 |      public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { | 
| 777 | 777 | |
| 778 | 778 | // In case we have validated the form, use it to inject the validation results into the form render | 
| 779 | -        if( isset( $this->form_after_validation ) ) { | |
| 779 | +        if ( isset( $this->form_after_validation ) ) { | |
| 780 | 780 | $form = $this->form_after_validation; | 
| 781 | 781 |          } else { | 
| 782 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); | |
| 782 | + $form[ 'fields' ] = $this->get_configured_edit_fields( $form, $this->view_id ); | |
| 783 | 783 | } | 
| 784 | 784 | |
| 785 | 785 | $form = $this->filter_conditional_logic( $form ); | 
| 786 | 786 | |
| 787 | 787 | // for now we don't support Save and Continue feature. | 
| 788 | -        if( ! self::$supports_save_and_continue ) { | |
| 789 | - unset( $form['save'] ); | |
| 788 | +        if ( ! self::$supports_save_and_continue ) { | |
| 789 | + unset( $form[ 'save' ] ); | |
| 790 | 790 | } | 
| 791 | 791 | |
| 792 | 792 | return $form; | 
| @@ -807,29 +807,29 @@ discard block | ||
| 807 | 807 | */ | 
| 808 | 808 |      function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { | 
| 809 | 809 | |
| 810 | -        if( GFCommon::is_post_field( $field ) ) { | |
| 810 | +        if ( GFCommon::is_post_field( $field ) ) { | |
| 811 | 811 | |
| 812 | 812 | $message = null; | 
| 813 | 813 | |
| 814 | 814 | // First, make sure they have the capability to edit the post. | 
| 815 | -            if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { | |
| 815 | +            if ( false === current_user_can( 'edit_post', $this->entry[ 'post_id' ] ) ) { | |
| 816 | 816 | |
| 817 | 817 | /** | 
| 818 | 818 | * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post | 
| 819 | 819 | * @param string $message The existing "You don't have permission..." text | 
| 820 | 820 | */ | 
| 821 | -                $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); | |
| 821 | + $message = apply_filters( 'gravityview/edit_entry/unsupported_post_field_text', __( 'You don’t have permission to edit this post.', 'gravityview' ) ); | |
| 822 | 822 | |
| 823 | -            } elseif( null === get_post( $this->entry['post_id'] ) ) { | |
| 823 | +            } elseif ( null === get_post( $this->entry[ 'post_id' ] ) ) { | |
| 824 | 824 | /** | 
| 825 | 825 | * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists | 
| 826 | 826 | * @param string $message The existing "This field is not editable; the post no longer exists." text | 
| 827 | 827 | */ | 
| 828 | -                $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); | |
| 828 | + $message = apply_filters( 'gravityview/edit_entry/no_post_text', __( 'This field is not editable; the post no longer exists.', 'gravityview' ) ); | |
| 829 | 829 | } | 
| 830 | 830 | |
| 831 | -            if( $message ) { | |
| 832 | -                $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); | |
| 831 | +            if ( $message ) { | |
| 832 | + $field_content = sprintf( '<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); | |
| 833 | 833 | } | 
| 834 | 834 | } | 
| 835 | 835 | |
| @@ -854,8 +854,8 @@ discard block | ||
| 854 | 854 | |
| 855 | 855 | // If the form has been submitted, then we don't need to pre-fill the values, | 
| 856 | 856 | // Except for fileupload type and when a field input is overridden- run always!! | 
| 857 | - if( | |
| 858 | - ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) | |
| 857 | + if ( | |
| 858 | + ( $this->is_edit_entry_submission() && ! in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) | |
| 859 | 859 | && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) | 
| 860 | 860 | || ! empty( $field_content ) | 
| 861 | 861 | || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable | 
| @@ -864,8 +864,8 @@ discard block | ||
| 864 | 864 | } | 
| 865 | 865 | |
| 866 | 866 | // Turn on Admin-style display for file upload fields only | 
| 867 | -        if( 'fileupload' === $field->type ) { | |
| 868 | - $_GET['page'] = 'gf_entries'; | |
| 867 | +        if ( 'fileupload' === $field->type ) { | |
| 868 | + $_GET[ 'page' ] = 'gf_entries'; | |
| 869 | 869 | } | 
| 870 | 870 | |
| 871 | 871 | // SET SOME FIELD DEFAULTS TO PREVENT ISSUES | 
| @@ -889,7 +889,7 @@ discard block | ||
| 889 | 889 | // Prevent any PHP warnings, like undefined index | 
| 890 | 890 | ob_start(); | 
| 891 | 891 | |
| 892 | -        if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { | |
| 892 | +        if ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { | |
| 893 | 893 | $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); | 
| 894 | 894 |          } else { | 
| 895 | 895 | $return = $field->get_field_input( $this->form, $field_value, $this->entry ); | 
| @@ -899,7 +899,7 @@ discard block | ||
| 899 | 899 | // If there was output, it's an error | 
| 900 | 900 | $warnings = ob_get_clean(); | 
| 901 | 901 | |
| 902 | -	    if( !empty( $warnings ) ) { | |
| 902 | +	    if ( ! empty( $warnings ) ) { | |
| 903 | 903 | do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); | 
| 904 | 904 | } | 
| 905 | 905 | |
| @@ -908,7 +908,7 @@ discard block | ||
| 908 | 908 | * We need the fileupload html field to render with the proper id | 
| 909 | 909 | * ( <li id="field_80_16" ... > ) | 
| 910 | 910 | */ | 
| 911 | - unset( $_GET['page'] ); | |
| 911 | + unset( $_GET[ 'page' ] ); | |
| 912 | 912 | |
| 913 | 913 | return $return; | 
| 914 | 914 | } | 
| @@ -931,7 +931,7 @@ discard block | ||
| 931 | 931 | $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); | 
| 932 | 932 | |
| 933 | 933 | // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) | 
| 934 | -        if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { | |
| 934 | +        if ( isset( $field->inputs ) && is_array( $field->inputs ) && ! in_array( $field->type, array( 'time', 'date' ) ) ) { | |
| 935 | 935 | |
| 936 | 936 | $field_value = array(); | 
| 937 | 937 | |
| @@ -940,10 +940,10 @@ discard block | ||
| 940 | 940 | |
| 941 | 941 |              foreach ( (array)$field->inputs as $input ) { | 
| 942 | 942 | |
| 943 | - $input_id = strval( $input['id'] ); | |
| 943 | + $input_id = strval( $input[ 'id' ] ); | |
| 944 | 944 | |
| 945 | 945 |                  if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { | 
| 946 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; | |
| 946 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; | |
| 947 | 947 | $allow_pre_populated = false; | 
| 948 | 948 | } | 
| 949 | 949 | |
| @@ -951,7 +951,7 @@ discard block | ||
| 951 | 951 | |
| 952 | 952 | $pre_value = $field->get_value_submission( array(), false ); | 
| 953 | 953 | |
| 954 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; | |
| 954 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && ! gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; | |
| 955 | 955 | |
| 956 | 956 |          } else { | 
| 957 | 957 | |
| @@ -962,13 +962,13 @@ discard block | ||
| 962 | 962 | |
| 963 | 963 | // saved field entry value (if empty, fallback to the pre-populated value, if exists) | 
| 964 | 964 | // or pre-populated value if not empty and set to override saved value | 
| 965 | - $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; | |
| 965 | + $field_value = ! gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && ! gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; | |
| 966 | 966 | |
| 967 | 967 | // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. | 
| 968 | -            if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { | |
| 968 | +            if ( 'post_category' === $field->type && ! gv_empty( $field_value, false, false ) ) { | |
| 969 | 969 | $categories = array(); | 
| 970 | 970 |                  foreach ( explode( ',', $field_value ) as $cat_string ) { | 
| 971 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); | |
| 971 | + $categories[ ] = GFCommon::format_post_category( $cat_string, true ); | |
| 972 | 972 | } | 
| 973 | 973 | $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); | 
| 974 | 974 | } | 
| @@ -993,12 +993,12 @@ discard block | ||
| 993 | 993 | */ | 
| 994 | 994 |      function gform_pre_validation( $form ) { | 
| 995 | 995 | |
| 996 | -        if( ! $this->verify_nonce() ) { | |
| 996 | +        if ( ! $this->verify_nonce() ) { | |
| 997 | 997 | return $form; | 
| 998 | 998 | } | 
| 999 | 999 | |
| 1000 | 1000 | // Fix PHP warning regarding undefined index. | 
| 1001 | -        foreach ( $form['fields'] as &$field) { | |
| 1001 | +        foreach ( $form[ 'fields' ] as &$field ) { | |
| 1002 | 1002 | |
| 1003 | 1003 | // This is because we're doing admin form pretending to be front-end, so Gravity Forms | 
| 1004 | 1004 | // expects certain field array items to be set. | 
| @@ -1011,7 +1011,7 @@ discard block | ||
| 1011 | 1011 | $field['emailConfirmEnabled'] = ''; | 
| 1012 | 1012 | }*/ | 
| 1013 | 1013 | |
| 1014 | -            switch( RGFormsModel::get_input_type( $field ) ) { | |
| 1014 | +            switch ( RGFormsModel::get_input_type( $field ) ) { | |
| 1015 | 1015 | |
| 1016 | 1016 | /** | 
| 1017 | 1017 | * 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. | 
| @@ -1025,37 +1025,37 @@ discard block | ||
| 1025 | 1025 | // Set the previous value | 
| 1026 | 1026 | $entry = $this->get_entry(); | 
| 1027 | 1027 | |
| 1028 | - $input_name = 'input_'.$field->id; | |
| 1029 | - $form_id = $form['id']; | |
| 1028 | + $input_name = 'input_' . $field->id; | |
| 1029 | + $form_id = $form[ 'id' ]; | |
| 1030 | 1030 | |
| 1031 | 1031 | $value = NULL; | 
| 1032 | 1032 | |
| 1033 | 1033 | // Use the previous entry value as the default. | 
| 1034 | -                    if( isset( $entry[ $field->id ] ) ) { | |
| 1034 | +                    if ( isset( $entry[ $field->id ] ) ) { | |
| 1035 | 1035 | $value = $entry[ $field->id ]; | 
| 1036 | 1036 | } | 
| 1037 | 1037 | |
| 1038 | 1038 | // If this is a single upload file | 
| 1039 | -                    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { | |
| 1040 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); | |
| 1041 | - $value = $file_path['url']; | |
| 1039 | +                    if ( ! empty( $_FILES[ $input_name ] ) && ! empty( $_FILES[ $input_name ][ 'name' ] ) ) { | |
| 1040 | + $file_path = GFFormsModel::get_file_upload_path( $form[ 'id' ], $_FILES[ $input_name ][ 'name' ] ); | |
| 1041 | + $value = $file_path[ 'url' ]; | |
| 1042 | 1042 | |
| 1043 | 1043 |                      } else { | 
| 1044 | 1044 | |
| 1045 | 1045 | // Fix PHP warning on line 1498 of form_display.php for post_image fields | 
| 1046 | 1046 | // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 | 
| 1047 | -                        $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); | |
| 1047 | + $_FILES[ $input_name ] = array( 'name' => '', 'size' => '' ); | |
| 1048 | 1048 | |
| 1049 | 1049 | } | 
| 1050 | 1050 | |
| 1051 | -                    if( rgar($field, "multipleFiles") ) { | |
| 1051 | +                    if ( rgar( $field, "multipleFiles" ) ) { | |
| 1052 | 1052 | |
| 1053 | 1053 | // If there are fresh uploads, process and merge them. | 
| 1054 | 1054 | // Otherwise, use the passed values, which should be json-encoded array of URLs | 
| 1055 | -                        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { | |
| 1055 | +                        if ( isset( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ) { | |
| 1056 | 1056 | $value = empty( $value ) ? '[]' : $value; | 
| 1057 | 1057 | $value = stripslashes_deep( $value ); | 
| 1058 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); | |
| 1058 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ], array() ); | |
| 1059 | 1059 | } | 
| 1060 | 1060 | |
| 1061 | 1061 |                      } else { | 
| @@ -1073,14 +1073,14 @@ discard block | ||
| 1073 | 1073 | |
| 1074 | 1074 | case 'number': | 
| 1075 | 1075 | // Fix "undefined index" issue at line 1286 in form_display.php | 
| 1076 | -                    if( !isset( $_POST['input_'.$field->id ] ) ) { | |
| 1077 | - $_POST['input_'.$field->id ] = NULL; | |
| 1076 | +                    if ( ! isset( $_POST[ 'input_' . $field->id ] ) ) { | |
| 1077 | + $_POST[ 'input_' . $field->id ] = NULL; | |
| 1078 | 1078 | } | 
| 1079 | 1079 | break; | 
| 1080 | 1080 | case 'captcha': | 
| 1081 | 1081 | // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php | 
| 1082 | - $_POST['recaptcha_challenge_field'] = NULL; | |
| 1083 | - $_POST['recaptcha_response_field'] = NULL; | |
| 1082 | + $_POST[ 'recaptcha_challenge_field' ] = NULL; | |
| 1083 | + $_POST[ 'recaptcha_response_field' ] = NULL; | |
| 1084 | 1084 | break; | 
| 1085 | 1085 | } | 
| 1086 | 1086 | |
| @@ -1116,7 +1116,7 @@ discard block | ||
| 1116 | 1116 | * You can enter whatever you want! | 
| 1117 | 1117 | * We try validating, and customize the results using `self::custom_validation()` | 
| 1118 | 1118 | */ | 
| 1119 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); | |
| 1119 | + add_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10, 4 ); | |
| 1120 | 1120 | |
| 1121 | 1121 | // Needed by the validate funtion | 
| 1122 | 1122 | $failed_validation_page = NULL; | 
| @@ -1124,14 +1124,14 @@ discard block | ||
| 1124 | 1124 | |
| 1125 | 1125 | // Prevent entry limit from running when editing an entry, also | 
| 1126 | 1126 | // prevent form scheduling from preventing editing | 
| 1127 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); | |
| 1127 | + unset( $this->form[ 'limitEntries' ], $this->form[ 'scheduleForm' ] ); | |
| 1128 | 1128 | |
| 1129 | 1129 | // Hide fields depending on Edit Entry settings | 
| 1130 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); | |
| 1130 | + $this->form[ 'fields' ] = $this->get_configured_edit_fields( $this->form, $this->view_id ); | |
| 1131 | 1131 | |
| 1132 | 1132 | $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); | 
| 1133 | 1133 | |
| 1134 | - remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); | |
| 1134 | + remove_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10 ); | |
| 1135 | 1135 | } | 
| 1136 | 1136 | |
| 1137 | 1137 | |
| @@ -1148,13 +1148,13 @@ discard block | ||
| 1148 | 1148 | */ | 
| 1149 | 1149 |      function custom_validation( $validation_results ) { | 
| 1150 | 1150 | |
| 1151 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); | |
| 1151 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); | |
| 1152 | 1152 | |
| 1153 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 1153 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 1154 | 1154 | |
| 1155 | 1155 | $gv_valid = true; | 
| 1156 | 1156 | |
| 1157 | -        foreach ( $validation_results['form']['fields'] as $key => &$field ) { | |
| 1157 | +        foreach ( $validation_results[ 'form' ][ 'fields' ] as $key => &$field ) { | |
| 1158 | 1158 | |
| 1159 | 1159 | $value = RGFormsModel::get_field_value( $field ); | 
| 1160 | 1160 | $field_type = RGFormsModel::get_input_type( $field ); | 
| @@ -1167,35 +1167,35 @@ discard block | ||
| 1167 | 1167 | case 'post_image': | 
| 1168 | 1168 | |
| 1169 | 1169 | // in case nothing is uploaded but there are already files saved | 
| 1170 | -                    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { | |
| 1170 | +                    if ( ! empty( $field->failed_validation ) && ! empty( $field->isRequired ) && ! empty( $value ) ) { | |
| 1171 | 1171 | $field->failed_validation = false; | 
| 1172 | 1172 | unset( $field->validation_message ); | 
| 1173 | 1173 | } | 
| 1174 | 1174 | |
| 1175 | 1175 | // validate if multi file upload reached max number of files [maxFiles] => 2 | 
| 1176 | -                    if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { | |
| 1176 | +                    if ( rgobj( $field, 'maxFiles' ) && rgobj( $field, 'multipleFiles' ) ) { | |
| 1177 | 1177 | |
| 1178 | 1178 | $input_name = 'input_' . $field->id; | 
| 1179 | 1179 | //uploaded | 
| 1180 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); | |
| 1180 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] : array(); | |
| 1181 | 1181 | |
| 1182 | 1182 | //existent | 
| 1183 | 1183 | $entry = $this->get_entry(); | 
| 1184 | 1184 | $value = NULL; | 
| 1185 | -                        if( isset( $entry[ $field->id ] ) ) { | |
| 1185 | +                        if ( isset( $entry[ $field->id ] ) ) { | |
| 1186 | 1186 | $value = json_decode( $entry[ $field->id ], true ); | 
| 1187 | 1187 | } | 
| 1188 | 1188 | |
| 1189 | 1189 | // count uploaded files and existent entry files | 
| 1190 | 1190 | $count_files = count( $file_names ) + count( $value ); | 
| 1191 | 1191 | |
| 1192 | -                        if( $count_files > $field->maxFiles ) { | |
| 1192 | +                        if ( $count_files > $field->maxFiles ) { | |
| 1193 | 1193 | $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); | 
| 1194 | 1194 | $field->failed_validation = 1; | 
| 1195 | 1195 | $gv_valid = false; | 
| 1196 | 1196 | |
| 1197 | 1197 | // in case of error make sure the newest upload files are removed from the upload input | 
| 1198 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; | |
| 1198 | + GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ] = null; | |
| 1199 | 1199 | } | 
| 1200 | 1200 | |
| 1201 | 1201 | } | 
| @@ -1206,7 +1206,7 @@ discard block | ||
| 1206 | 1206 | } | 
| 1207 | 1207 | |
| 1208 | 1208 | // This field has failed validation. | 
| 1209 | -            if( !empty( $field->failed_validation ) ) { | |
| 1209 | +            if ( ! empty( $field->failed_validation ) ) { | |
| 1210 | 1210 | |
| 1211 | 1211 | do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); | 
| 1212 | 1212 | |
| @@ -1224,32 +1224,32 @@ discard block | ||
| 1224 | 1224 | } | 
| 1225 | 1225 | |
| 1226 | 1226 | // You can't continue inside a switch, so we do it after. | 
| 1227 | -                if( empty( $field->failed_validation ) ) { | |
| 1227 | +                if ( empty( $field->failed_validation ) ) { | |
| 1228 | 1228 | continue; | 
| 1229 | 1229 | } | 
| 1230 | 1230 | |
| 1231 | 1231 | // checks if the No Duplicates option is not validating entry against itself, since | 
| 1232 | 1232 | // we're editing a stored entry, it would also assume it's a duplicate. | 
| 1233 | -                if( !empty( $field->noDuplicates ) ) { | |
| 1233 | +                if ( ! empty( $field->noDuplicates ) ) { | |
| 1234 | 1234 | |
| 1235 | 1235 | $entry = $this->get_entry(); | 
| 1236 | 1236 | |
| 1237 | 1237 | // If the value of the entry is the same as the stored value | 
| 1238 | 1238 | // Then we can assume it's not a duplicate, it's the same. | 
| 1239 | -                    if( !empty( $entry ) && $value == $entry[ $field->id ] ) { | |
| 1239 | +                    if ( ! empty( $entry ) && $value == $entry[ $field->id ] ) { | |
| 1240 | 1240 | //if value submitted was not changed, then don't validate | 
| 1241 | 1241 | $field->failed_validation = false; | 
| 1242 | 1242 | |
| 1243 | 1243 | unset( $field->validation_message ); | 
| 1244 | 1244 | |
| 1245 | -                        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); | |
| 1245 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); | |
| 1246 | 1246 | |
| 1247 | 1247 | continue; | 
| 1248 | 1248 | } | 
| 1249 | 1249 | } | 
| 1250 | 1250 | |
| 1251 | 1251 | // if here then probably we are facing the validation 'At least one field must be filled out' | 
| 1252 | -                if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) { | |
| 1252 | +                if ( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { | |
| 1253 | 1253 | unset( $field->validation_message ); | 
| 1254 | 1254 | $field->validation_message = false; | 
| 1255 | 1255 | continue; | 
| @@ -1261,12 +1261,12 @@ discard block | ||
| 1261 | 1261 | |
| 1262 | 1262 | } | 
| 1263 | 1263 | |
| 1264 | - $validation_results['is_valid'] = $gv_valid; | |
| 1264 | + $validation_results[ 'is_valid' ] = $gv_valid; | |
| 1265 | 1265 | |
| 1266 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); | |
| 1266 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); | |
| 1267 | 1267 | |
| 1268 | 1268 | // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) | 
| 1269 | - $this->form_after_validation = $validation_results['form']; | |
| 1269 | + $this->form_after_validation = $validation_results[ 'form' ]; | |
| 1270 | 1270 | |
| 1271 | 1271 | return $validation_results; | 
| 1272 | 1272 | } | 
| @@ -1279,7 +1279,7 @@ discard block | ||
| 1279 | 1279 | */ | 
| 1280 | 1280 |      private function get_entry() { | 
| 1281 | 1281 | |
| 1282 | -        if( empty( $this->entry ) ) { | |
| 1282 | +        if ( empty( $this->entry ) ) { | |
| 1283 | 1283 | // Get the database value of the entry that's being edited | 
| 1284 | 1284 | $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); | 
| 1285 | 1285 | } | 
| @@ -1306,13 +1306,13 @@ discard block | ||
| 1306 | 1306 | $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); | 
| 1307 | 1307 | |
| 1308 | 1308 | // If edit tab not yet configured, show all fields | 
| 1309 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; | |
| 1309 | + $edit_fields = ! empty( $properties[ 'edit_edit-fields' ] ) ? $properties[ 'edit_edit-fields' ] : NULL; | |
| 1310 | 1310 | |
| 1311 | 1311 | // Show hidden fields as text fields | 
| 1312 | 1312 | $form = $this->fix_hidden_fields( $form ); | 
| 1313 | 1313 | |
| 1314 | 1314 | // Hide fields depending on admin settings | 
| 1315 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); | |
| 1315 | + $fields = $this->filter_fields( $form[ 'fields' ], $edit_fields ); | |
| 1316 | 1316 | |
| 1317 | 1317 | // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. | 
| 1318 | 1318 | $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); | 
| @@ -1330,11 +1330,11 @@ discard block | ||
| 1330 | 1330 |  	private function fix_hidden_fields( $form ) { | 
| 1331 | 1331 | |
| 1332 | 1332 | /** @var GF_Field $field */ | 
| 1333 | -		foreach( $form['fields'] as $key => $field ) { | |
| 1334 | -			if( 'hidden' === $field->type ) { | |
| 1333 | +		foreach ( $form[ 'fields' ] as $key => $field ) { | |
| 1334 | +			if ( 'hidden' === $field->type ) { | |
| 1335 | 1335 | $text_field = new GF_Field_Text( $field ); | 
| 1336 | 1336 | $text_field->type = 'text'; | 
| 1337 | - $form['fields'][ $key ] = $text_field; | |
| 1337 | + $form[ 'fields' ][ $key ] = $text_field; | |
| 1338 | 1338 | } | 
| 1339 | 1339 | } | 
| 1340 | 1340 | |
| @@ -1355,7 +1355,7 @@ discard block | ||
| 1355 | 1355 | */ | 
| 1356 | 1356 |      private function filter_fields( $fields, $configured_fields ) { | 
| 1357 | 1357 | |
| 1358 | -        if( empty( $fields ) || !is_array( $fields ) ) { | |
| 1358 | +        if ( empty( $fields ) || ! is_array( $fields ) ) { | |
| 1359 | 1359 | return $fields; | 
| 1360 | 1360 | } | 
| 1361 | 1361 | |
| @@ -1372,13 +1372,13 @@ discard block | ||
| 1372 | 1372 | */ | 
| 1373 | 1373 | $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); | 
| 1374 | 1374 | |
| 1375 | -	    if( $hide_product_fields ) { | |
| 1376 | - $field_type_blacklist[] = 'option'; | |
| 1377 | - $field_type_blacklist[] = 'quantity'; | |
| 1378 | - $field_type_blacklist[] = 'product'; | |
| 1379 | - $field_type_blacklist[] = 'total'; | |
| 1380 | - $field_type_blacklist[] = 'shipping'; | |
| 1381 | - $field_type_blacklist[] = 'calculation'; | |
| 1375 | +	    if ( $hide_product_fields ) { | |
| 1376 | + $field_type_blacklist[ ] = 'option'; | |
| 1377 | + $field_type_blacklist[ ] = 'quantity'; | |
| 1378 | + $field_type_blacklist[ ] = 'product'; | |
| 1379 | + $field_type_blacklist[ ] = 'total'; | |
| 1380 | + $field_type_blacklist[ ] = 'shipping'; | |
| 1381 | + $field_type_blacklist[ ] = 'calculation'; | |
| 1382 | 1382 | } | 
| 1383 | 1383 | |
| 1384 | 1384 | // First, remove blacklist or calculation fields | 
| @@ -1386,17 +1386,17 @@ discard block | ||
| 1386 | 1386 | |
| 1387 | 1387 | // Remove the fields that have calculation properties | 
| 1388 | 1388 | // @since 1.16.2 | 
| 1389 | -            if( $field->has_calculation() ) { | |
| 1389 | +            if ( $field->has_calculation() ) { | |
| 1390 | 1390 | unset( $fields[ $key ] ); | 
| 1391 | 1391 | } | 
| 1392 | 1392 | |
| 1393 | -            if( in_array( $field->type, $field_type_blacklist ) ) { | |
| 1393 | +            if ( in_array( $field->type, $field_type_blacklist ) ) { | |
| 1394 | 1394 | unset( $fields[ $key ] ); | 
| 1395 | 1395 | } | 
| 1396 | 1396 | } | 
| 1397 | 1397 | |
| 1398 | 1398 | // The Edit tab has not been configured, so we return all fields by default. | 
| 1399 | -        if( empty( $configured_fields ) ) { | |
| 1399 | +        if ( empty( $configured_fields ) ) { | |
| 1400 | 1400 | return $fields; | 
| 1401 | 1401 | } | 
| 1402 | 1402 | |
| @@ -1406,8 +1406,8 @@ discard block | ||
| 1406 | 1406 | /** @var GF_Field $field */ | 
| 1407 | 1407 |  	        foreach ( $fields as $field ) { | 
| 1408 | 1408 | |
| 1409 | -                if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { | |
| 1410 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); | |
| 1409 | +                if ( intval( $configured_field[ 'id' ] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { | |
| 1410 | + $edit_fields[ ] = $this->merge_field_properties( $field, $configured_field ); | |
| 1411 | 1411 | break; | 
| 1412 | 1412 | } | 
| 1413 | 1413 | |
| @@ -1430,14 +1430,14 @@ discard block | ||
| 1430 | 1430 | |
| 1431 | 1431 | $return_field = $field; | 
| 1432 | 1432 | |
| 1433 | -        if( empty( $field_setting['show_label'] ) ) { | |
| 1433 | +        if ( empty( $field_setting[ 'show_label' ] ) ) { | |
| 1434 | 1434 | $return_field->label = ''; | 
| 1435 | -        } elseif ( !empty( $field_setting['custom_label'] ) ) { | |
| 1436 | - $return_field->label = $field_setting['custom_label']; | |
| 1435 | +        } elseif ( ! empty( $field_setting[ 'custom_label' ] ) ) { | |
| 1436 | + $return_field->label = $field_setting[ 'custom_label' ]; | |
| 1437 | 1437 | } | 
| 1438 | 1438 | |
| 1439 | -        if( !empty( $field_setting['custom_class'] ) ) { | |
| 1440 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); | |
| 1439 | +        if ( ! empty( $field_setting[ 'custom_class' ] ) ) { | |
| 1440 | + $return_field->cssClass .= ' ' . gravityview_sanitize_html_class( $field_setting[ 'custom_class' ] ); | |
| 1441 | 1441 | } | 
| 1442 | 1442 | |
| 1443 | 1443 | /** | 
| @@ -1475,16 +1475,16 @@ discard block | ||
| 1475 | 1475 | */ | 
| 1476 | 1476 | $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); | 
| 1477 | 1477 | |
| 1478 | -	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { | |
| 1479 | -            foreach( $fields as $k => $field ) { | |
| 1480 | -                if( $field->adminOnly ) { | |
| 1478 | +	    if ( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry[ 'id' ] ) ) { | |
| 1479 | +            foreach ( $fields as $k => $field ) { | |
| 1480 | +                if ( $field->adminOnly ) { | |
| 1481 | 1481 | unset( $fields[ $k ] ); | 
| 1482 | 1482 | } | 
| 1483 | 1483 | } | 
| 1484 | 1484 | return $fields; | 
| 1485 | 1485 | } | 
| 1486 | 1486 | |
| 1487 | -	    foreach( $fields as &$field ) { | |
| 1487 | +	    foreach ( $fields as &$field ) { | |
| 1488 | 1488 | $field->adminOnly = false; | 
| 1489 | 1489 | } | 
| 1490 | 1490 | |
| @@ -1511,16 +1511,16 @@ discard block | ||
| 1511 | 1511 | */ | 
| 1512 | 1512 | $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); | 
| 1513 | 1513 | |
| 1514 | -        if( $use_conditional_logic ) { | |
| 1514 | +        if ( $use_conditional_logic ) { | |
| 1515 | 1515 | return $form; | 
| 1516 | 1516 | } | 
| 1517 | 1517 | |
| 1518 | -        foreach( $form['fields'] as &$field ) { | |
| 1518 | +        foreach ( $form[ 'fields' ] as &$field ) { | |
| 1519 | 1519 | /* @var GF_Field $field */ | 
| 1520 | 1520 | $field->conditionalLogic = null; | 
| 1521 | 1521 | } | 
| 1522 | 1522 | |
| 1523 | - unset( $form['button']['conditionalLogic'] ); | |
| 1523 | + unset( $form[ 'button' ][ 'conditionalLogic' ] ); | |
| 1524 | 1524 | |
| 1525 | 1525 | return $form; | 
| 1526 | 1526 | |
| @@ -1537,7 +1537,7 @@ discard block | ||
| 1537 | 1537 | */ | 
| 1538 | 1538 |      function manage_conditional_logic( $has_conditional_logic, $form ) { | 
| 1539 | 1539 | |
| 1540 | -        if( ! $this->is_edit_entry() ) { | |
| 1540 | +        if ( ! $this->is_edit_entry() ) { | |
| 1541 | 1541 | return $has_conditional_logic; | 
| 1542 | 1542 | } | 
| 1543 | 1543 | |
| @@ -1568,44 +1568,44 @@ discard block | ||
| 1568 | 1568 | * 2. There are two entries embedded using oEmbed | 
| 1569 | 1569 | * 3. One of the entries has just been saved | 
| 1570 | 1570 | */ | 
| 1571 | -        if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { | |
| 1571 | +        if ( ! empty( $_POST[ 'lid' ] ) && ! empty( $_GET[ 'entry' ] ) && ( $_POST[ 'lid' ] !== $_GET[ 'entry' ] ) ) { | |
| 1572 | 1572 | |
| 1573 | 1573 | $error = true; | 
| 1574 | 1574 | |
| 1575 | 1575 | } | 
| 1576 | 1576 | |
| 1577 | -        if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { | |
| 1577 | +        if ( ! empty( $_GET[ 'entry' ] ) && (string)$this->entry[ 'id' ] !== $_GET[ 'entry' ] ) { | |
| 1578 | 1578 | |
| 1579 | 1579 | $error = true; | 
| 1580 | 1580 | |
| 1581 | -        } elseif( ! $this->verify_nonce() ) { | |
| 1581 | +        } elseif ( ! $this->verify_nonce() ) { | |
| 1582 | 1582 | |
| 1583 | 1583 | /** | 
| 1584 | 1584 | * If the Entry is embedded, there may be two entries on the same page. | 
| 1585 | 1585 | * If that's the case, and one is being edited, the other should fail gracefully and not display an error. | 
| 1586 | 1586 | */ | 
| 1587 | -            if( GravityView_oEmbed::getInstance()->get_entry_id() ) { | |
| 1587 | +            if ( GravityView_oEmbed::getInstance()->get_entry_id() ) { | |
| 1588 | 1588 | $error = true; | 
| 1589 | 1589 |              } else { | 
| 1590 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); | |
| 1590 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview' ); | |
| 1591 | 1591 | } | 
| 1592 | 1592 | |
| 1593 | 1593 | } | 
| 1594 | 1594 | |
| 1595 | -        if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { | |
| 1596 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); | |
| 1595 | +        if ( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { | |
| 1596 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview' ); | |
| 1597 | 1597 | } | 
| 1598 | 1598 | |
| 1599 | -        if( $this->entry['status'] === 'trash' ) { | |
| 1600 | -            $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); | |
| 1599 | +        if ( $this->entry[ 'status' ] === 'trash' ) { | |
| 1600 | + $error = __( 'You cannot edit the entry; it is in the trash.', 'gravityview' ); | |
| 1601 | 1601 | } | 
| 1602 | 1602 | |
| 1603 | 1603 | // No errors; everything's fine here! | 
| 1604 | -        if( empty( $error ) ) { | |
| 1604 | +        if ( empty( $error ) ) { | |
| 1605 | 1605 | return true; | 
| 1606 | 1606 | } | 
| 1607 | 1607 | |
| 1608 | -        if( $echo && $error !== true ) { | |
| 1608 | +        if ( $echo && $error !== true ) { | |
| 1609 | 1609 | |
| 1610 | 1610 | $error = esc_html( $error ); | 
| 1611 | 1611 | |
| @@ -1613,13 +1613,13 @@ discard block | ||
| 1613 | 1613 | * @since 1.9 | 
| 1614 | 1614 | */ | 
| 1615 | 1615 |  	        if ( ! empty( $this->entry ) ) { | 
| 1616 | -		        $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;" ) ); | |
| 1616 | + $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;" ) ); | |
| 1617 | 1617 | } | 
| 1618 | 1618 | |
| 1619 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); | |
| 1619 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error' ); | |
| 1620 | 1620 | } | 
| 1621 | 1621 | |
| 1622 | -        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); | |
| 1622 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); | |
| 1623 | 1623 | |
| 1624 | 1624 | return false; | 
| 1625 | 1625 | } | 
| @@ -1636,20 +1636,20 @@ discard block | ||
| 1636 | 1636 | |
| 1637 | 1637 | $error = NULL; | 
| 1638 | 1638 | |
| 1639 | -        if( ! $this->check_user_cap_edit_field( $field ) ) { | |
| 1640 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); | |
| 1639 | +        if ( ! $this->check_user_cap_edit_field( $field ) ) { | |
| 1640 | + $error = __( 'You do not have permission to edit this field.', 'gravityview' ); | |
| 1641 | 1641 | } | 
| 1642 | 1642 | |
| 1643 | 1643 | // No errors; everything's fine here! | 
| 1644 | -        if( empty( $error ) ) { | |
| 1644 | +        if ( empty( $error ) ) { | |
| 1645 | 1645 | return true; | 
| 1646 | 1646 | } | 
| 1647 | 1647 | |
| 1648 | -        if( $echo ) { | |
| 1649 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); | |
| 1648 | +        if ( $echo ) { | |
| 1649 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error' ); | |
| 1650 | 1650 | } | 
| 1651 | 1651 | |
| 1652 | -        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); | |
| 1652 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); | |
| 1653 | 1653 | |
| 1654 | 1654 | return false; | 
| 1655 | 1655 | |
| @@ -1667,15 +1667,15 @@ discard block | ||
| 1667 | 1667 |      private function check_user_cap_edit_field( $field ) { | 
| 1668 | 1668 | |
| 1669 | 1669 | // If they can edit any entries (as defined in Gravity Forms), we're good. | 
| 1670 | -        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { | |
| 1670 | +        if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { | |
| 1671 | 1671 | return true; | 
| 1672 | 1672 | } | 
| 1673 | 1673 | |
| 1674 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; | |
| 1674 | + $field_cap = isset( $field[ 'allow_edit_cap' ] ) ? $field[ 'allow_edit_cap' ] : false; | |
| 1675 | 1675 | |
| 1676 | 1676 | // If the field has custom editing capaibilities set, check those | 
| 1677 | -        if( $field_cap ) { | |
| 1678 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); | |
| 1677 | +        if ( $field_cap ) { | |
| 1678 | + return GVCommon::has_cap( $field[ 'allow_edit_cap' ] ); | |
| 1679 | 1679 | } | 
| 1680 | 1680 | |
| 1681 | 1681 | return false; | 
| @@ -1689,17 +1689,17 @@ discard block | ||
| 1689 | 1689 |      public function verify_nonce() { | 
| 1690 | 1690 | |
| 1691 | 1691 | // Verify form submitted for editing single | 
| 1692 | -        if( $this->is_edit_entry_submission() ) { | |
| 1692 | +        if ( $this->is_edit_entry_submission() ) { | |
| 1693 | 1693 | $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); | 
| 1694 | 1694 | } | 
| 1695 | 1695 | |
| 1696 | 1696 | // Verify | 
| 1697 | -        else if( ! $this->is_edit_entry() ) { | |
| 1697 | +        else if ( ! $this->is_edit_entry() ) { | |
| 1698 | 1698 | $valid = false; | 
| 1699 | 1699 | } | 
| 1700 | 1700 | |
| 1701 | 1701 |          else { | 
| 1702 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); | |
| 1702 | + $valid = wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ); | |
| 1703 | 1703 | } | 
| 1704 | 1704 | |
| 1705 | 1705 | /** | 
| @@ -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,130 +44,130 @@ discard block | ||
| 44 | 44 | */ | 
| 45 | 45 | private static $supports_product_fields = false; | 
| 46 | 46 | |
| 47 | - /** | |
| 48 | - * Gravity Forms entry array | |
| 49 | - * | |
| 50 | - * @var array | |
| 51 | - */ | |
| 52 | - var $entry; | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * Gravity Forms form array (GravityView modifies the content through this class lifecycle) | |
| 56 | - * | |
| 57 | - * @var array | |
| 58 | - */ | |
| 59 | - var $form; | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * Gravity Forms form array (it won't get changed during this class lifecycle) | |
| 63 | - * @since 1.16.3 | |
| 64 | - * @var array | |
| 65 | - */ | |
| 66 | - var $original_form; | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * Gravity Forms form array after the form validation process | |
| 70 | - * @since 1.13 | |
| 71 | - * @var array | |
| 72 | - */ | |
| 73 | - var $form_after_validation = null; | |
| 74 | - | |
| 75 | - /** | |
| 76 | - * Gravity Forms form id | |
| 77 | - * | |
| 78 | - * @var int | |
| 79 | - */ | |
| 80 | - var $form_id; | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * ID of the current view | |
| 84 | - * | |
| 85 | - * @var int | |
| 86 | - */ | |
| 87 | - var $view_id; | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * Updated entry is valid (GF Validation object) | |
| 91 | - * | |
| 92 | - * @var array | |
| 93 | - */ | |
| 94 | - var $is_valid = NULL; | |
| 95 | - | |
| 96 | -    function __construct( GravityView_Edit_Entry $loader ) { | |
| 97 | - $this->loader = $loader; | |
| 98 | - } | |
| 99 | - | |
| 100 | -    function load() { | |
| 101 | - | |
| 102 | - /** @define "GRAVITYVIEW_DIR" "../../../" */ | |
| 103 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); | |
| 104 | - | |
| 105 | - // Don't display an embedded form when editing an entry | |
| 106 | - add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); | |
| 107 | - add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); | |
| 108 | - | |
| 109 | - // Stop Gravity Forms processing what is ours! | |
| 110 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); | |
| 111 | - | |
| 112 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); | |
| 113 | - | |
| 114 | - add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); | |
| 115 | - | |
| 116 | - // Disable conditional logic if needed (since 1.9) | |
| 117 | - add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); | |
| 118 | - | |
| 119 | - // Make sure GF doesn't validate max files (since 1.9) | |
| 120 | - add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); | |
| 121 | - | |
| 122 | - // Add fields expected by GFFormDisplay::validate() | |
| 123 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); | |
| 124 | - | |
| 125 | - } | |
| 126 | - | |
| 127 | - /** | |
| 128 | - * Don't show any forms embedded on a page when GravityView is in Edit Entry mode | |
| 129 | - * | |
| 130 | - * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action | |
| 131 | - * And then removes it on the `wp_footer` action | |
| 132 | - * | |
| 133 | - * @since 1.16.1 | |
| 134 | - * | |
| 135 | - * @return void | |
| 136 | - */ | |
| 137 | -    function prevent_render_form() { | |
| 138 | -        if( $this->is_edit_entry() ) { | |
| 139 | -            if( 'wp_head' === current_filter() ) { | |
| 140 | - add_filter( 'gform_shortcode_form', '__return_empty_string' ); | |
| 141 | -            } else { | |
| 142 | - remove_filter( 'gform_shortcode_form', '__return_empty_string' ); | |
| 143 | - } | |
| 144 | - } | |
| 145 | - } | |
| 146 | - | |
| 147 | - /** | |
| 148 | - * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms | |
| 149 | - * backend form, we need to prevent them from saving twice. | |
| 150 | - * @return void | |
| 151 | - */ | |
| 152 | -    function prevent_maybe_process_form() { | |
| 153 | - | |
| 154 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 155 | - | |
| 156 | -        if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { | |
| 157 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); | |
| 158 | - } | |
| 159 | - } | |
| 160 | - | |
| 161 | - /** | |
| 162 | - * Is the current page an Edit Entry page? | |
| 163 | - * @return boolean | |
| 164 | - */ | |
| 165 | -    public function is_edit_entry() { | |
| 166 | - | |
| 167 | - $gf_page = ( 'entry' === RGForms::get( 'view' ) ); | |
| 168 | - | |
| 169 | - return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); | |
| 170 | - } | |
| 47 | + /** | |
| 48 | + * Gravity Forms entry array | |
| 49 | + * | |
| 50 | + * @var array | |
| 51 | + */ | |
| 52 | + var $entry; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Gravity Forms form array (GravityView modifies the content through this class lifecycle) | |
| 56 | + * | |
| 57 | + * @var array | |
| 58 | + */ | |
| 59 | + var $form; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Gravity Forms form array (it won't get changed during this class lifecycle) | |
| 63 | + * @since 1.16.3 | |
| 64 | + * @var array | |
| 65 | + */ | |
| 66 | + var $original_form; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Gravity Forms form array after the form validation process | |
| 70 | + * @since 1.13 | |
| 71 | + * @var array | |
| 72 | + */ | |
| 73 | + var $form_after_validation = null; | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Gravity Forms form id | |
| 77 | + * | |
| 78 | + * @var int | |
| 79 | + */ | |
| 80 | + var $form_id; | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * ID of the current view | |
| 84 | + * | |
| 85 | + * @var int | |
| 86 | + */ | |
| 87 | + var $view_id; | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Updated entry is valid (GF Validation object) | |
| 91 | + * | |
| 92 | + * @var array | |
| 93 | + */ | |
| 94 | + var $is_valid = NULL; | |
| 95 | + | |
| 96 | +	function __construct( GravityView_Edit_Entry $loader ) { | |
| 97 | + $this->loader = $loader; | |
| 98 | + } | |
| 99 | + | |
| 100 | +	function load() { | |
| 101 | + | |
| 102 | + /** @define "GRAVITYVIEW_DIR" "../../../" */ | |
| 103 | + include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); | |
| 104 | + | |
| 105 | + // Don't display an embedded form when editing an entry | |
| 106 | + add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); | |
| 107 | + add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); | |
| 108 | + | |
| 109 | + // Stop Gravity Forms processing what is ours! | |
| 110 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); | |
| 111 | + | |
| 112 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); | |
| 113 | + | |
| 114 | + add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); | |
| 115 | + | |
| 116 | + // Disable conditional logic if needed (since 1.9) | |
| 117 | + add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); | |
| 118 | + | |
| 119 | + // Make sure GF doesn't validate max files (since 1.9) | |
| 120 | + add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); | |
| 121 | + | |
| 122 | + // Add fields expected by GFFormDisplay::validate() | |
| 123 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); | |
| 124 | + | |
| 125 | + } | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * Don't show any forms embedded on a page when GravityView is in Edit Entry mode | |
| 129 | + * | |
| 130 | + * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action | |
| 131 | + * And then removes it on the `wp_footer` action | |
| 132 | + * | |
| 133 | + * @since 1.16.1 | |
| 134 | + * | |
| 135 | + * @return void | |
| 136 | + */ | |
| 137 | +	function prevent_render_form() { | |
| 138 | +		if( $this->is_edit_entry() ) { | |
| 139 | +			if( 'wp_head' === current_filter() ) { | |
| 140 | + add_filter( 'gform_shortcode_form', '__return_empty_string' ); | |
| 141 | +			} else { | |
| 142 | + remove_filter( 'gform_shortcode_form', '__return_empty_string' ); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms | |
| 149 | + * backend form, we need to prevent them from saving twice. | |
| 150 | + * @return void | |
| 151 | + */ | |
| 152 | +	function prevent_maybe_process_form() { | |
| 153 | + | |
| 154 | +		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 155 | + | |
| 156 | +		if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { | |
| 157 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); | |
| 158 | + } | |
| 159 | + } | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * Is the current page an Edit Entry page? | |
| 163 | + * @return boolean | |
| 164 | + */ | |
| 165 | +	public function is_edit_entry() { | |
| 166 | + | |
| 167 | + $gf_page = ( 'entry' === RGForms::get( 'view' ) ); | |
| 168 | + | |
| 169 | + return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' ); | |
| 170 | + } | |
| 171 | 171 | |
| 172 | 172 | /** | 
| 173 | 173 | * Is the current page an Edit Entry page? | 
| @@ -178,469 +178,469 @@ discard block | ||
| 178 | 178 | return !empty( $_POST[ self::$nonce_field ] ); | 
| 179 | 179 | } | 
| 180 | 180 | |
| 181 | - /** | |
| 182 | - * When Edit entry view is requested setup the vars | |
| 183 | - */ | |
| 184 | -    function setup_vars() { | |
| 185 | - $gravityview_view = GravityView_View::getInstance(); | |
| 181 | + /** | |
| 182 | + * When Edit entry view is requested setup the vars | |
| 183 | + */ | |
| 184 | +	function setup_vars() { | |
| 185 | + $gravityview_view = GravityView_View::getInstance(); | |
| 186 | + | |
| 186 | 187 | |
| 188 | + $entries = $gravityview_view->getEntries(); | |
| 189 | + $this->entry = $entries[0]; | |
| 190 | + | |
| 191 | + $this->original_form = $this->form = $gravityview_view->getForm(); | |
| 192 | + $this->form_id = $gravityview_view->getFormId(); | |
| 193 | + $this->view_id = $gravityview_view->getViewId(); | |
| 194 | + | |
| 195 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); | |
| 196 | + } | |
| 187 | 197 | |
| 188 | - $entries = $gravityview_view->getEntries(); | |
| 189 | - $this->entry = $entries[0]; | |
| 190 | 198 | |
| 191 | - $this->original_form = $this->form = $gravityview_view->getForm(); | |
| 192 | - $this->form_id = $gravityview_view->getFormId(); | |
| 193 | - $this->view_id = $gravityview_view->getViewId(); | |
| 199 | + /** | |
| 200 | + * Load required files and trigger edit flow | |
| 201 | + * | |
| 202 | + * Run when the is_edit_entry returns true. | |
| 203 | + * | |
| 204 | + * @param GravityView_View_Data $gv_data GravityView Data object | |
| 205 | + * @return void | |
| 206 | + */ | |
| 207 | +	function init( $gv_data ) { | |
| 194 | 208 | |
| 195 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); | |
| 196 | - } | |
| 209 | + require_once( GFCommon::get_base_path() . '/form_display.php' ); | |
| 210 | + require_once( GFCommon::get_base_path() . '/entry_detail.php' ); | |
| 197 | 211 | |
| 212 | + $this->setup_vars(); | |
| 198 | 213 | |
| 199 | - /** | |
| 200 | - * Load required files and trigger edit flow | |
| 201 | - * | |
| 202 | - * Run when the is_edit_entry returns true. | |
| 203 | - * | |
| 204 | - * @param GravityView_View_Data $gv_data GravityView Data object | |
| 205 | - * @return void | |
| 206 | - */ | |
| 207 | -    function init( $gv_data ) { | |
| 214 | + // Multiple Views embedded, don't proceed if nonce fails | |
| 215 | +		if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { | |
| 216 | + return; | |
| 217 | + } | |
| 208 | 218 | |
| 209 | - require_once( GFCommon::get_base_path() . '/form_display.php' ); | |
| 210 | - require_once( GFCommon::get_base_path() . '/entry_detail.php' ); | |
| 219 | + // Sorry, you're not allowed here. | |
| 220 | +		if( false === $this->user_can_edit_entry( true ) ) { | |
| 221 | + return; | |
| 222 | + } | |
| 211 | 223 | |
| 212 | - $this->setup_vars(); | |
| 224 | + $this->print_scripts(); | |
| 213 | 225 | |
| 214 | - // Multiple Views embedded, don't proceed if nonce fails | |
| 215 | -        if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { | |
| 216 | - return; | |
| 217 | - } | |
| 226 | + $this->process_save(); | |
| 218 | 227 | |
| 219 | - // Sorry, you're not allowed here. | |
| 220 | -        if( false === $this->user_can_edit_entry( true ) ) { | |
| 221 | - return; | |
| 222 | - } | |
| 228 | + $this->edit_entry_form(); | |
| 223 | 229 | |
| 224 | - $this->print_scripts(); | |
| 230 | + } | |
| 225 | 231 | |
| 226 | - $this->process_save(); | |
| 227 | 232 | |
| 228 | - $this->edit_entry_form(); | |
| 233 | + /** | |
| 234 | + * Force Gravity Forms to output scripts as if it were in the admin | |
| 235 | + * @return void | |
| 236 | + */ | |
| 237 | +	function print_scripts() { | |
| 238 | + $gravityview_view = GravityView_View::getInstance(); | |
| 229 | 239 | |
| 230 | - } | |
| 240 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); | |
| 231 | 241 | |
| 242 | + GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); | |
| 232 | 243 | |
| 233 | - /** | |
| 234 | - * Force Gravity Forms to output scripts as if it were in the admin | |
| 235 | - * @return void | |
| 236 | - */ | |
| 237 | -    function print_scripts() { | |
| 238 | - $gravityview_view = GravityView_View::getInstance(); | |
| 244 | + // Sack is required for images | |
| 245 | + wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); | |
| 246 | + } | |
| 239 | 247 | |
| 240 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); | |
| 241 | 248 | |
| 242 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); | |
| 249 | + /** | |
| 250 | + * Process edit entry form save | |
| 251 | + */ | |
| 252 | +	function process_save() { | |
| 243 | 253 | |
| 244 | - // Sack is required for images | |
| 245 | - wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); | |
| 246 | - } | |
| 254 | +		if( empty( $_POST ) ) { | |
| 255 | + return; | |
| 256 | + } | |
| 247 | 257 | |
| 258 | + // Make sure the entry, view, and form IDs are all correct | |
| 259 | + $valid = $this->verify_nonce(); | |
| 248 | 260 | |
| 249 | - /** | |
| 250 | - * Process edit entry form save | |
| 251 | - */ | |
| 252 | -    function process_save() { | |
| 261 | +		if( !$valid ) { | |
| 262 | +			do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); | |
| 263 | + return; | |
| 264 | + } | |
| 253 | 265 | |
| 254 | -        if( empty( $_POST ) ) { | |
| 255 | - return; | |
| 256 | - } | |
| 266 | +		if( $this->entry['id'] !== $_POST['lid'] ) { | |
| 267 | +			do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); | |
| 268 | + return; | |
| 269 | + } | |
| 257 | 270 | |
| 258 | - // Make sure the entry, view, and form IDs are all correct | |
| 259 | - $valid = $this->verify_nonce(); | |
| 271 | +		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 260 | 272 | |
| 261 | -        if( !$valid ) { | |
| 262 | -            do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); | |
| 263 | - return; | |
| 264 | - } | |
| 273 | + $this->process_save_process_files( $this->form_id ); | |
| 265 | 274 | |
| 266 | -        if( $this->entry['id'] !== $_POST['lid'] ) { | |
| 267 | -            do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); | |
| 268 | - return; | |
| 269 | - } | |
| 275 | + $this->validate(); | |
| 270 | 276 | |
| 271 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 277 | +		if( $this->is_valid ) { | |
| 272 | 278 | |
| 273 | - $this->process_save_process_files( $this->form_id ); | |
| 279 | +			do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); | |
| 274 | 280 | |
| 275 | - $this->validate(); | |
| 281 | + /** | |
| 282 | + * @hack This step is needed to unset the adminOnly from form fields | |
| 283 | + */ | |
| 284 | + $form = $this->form_prepare_for_save(); | |
| 276 | 285 | |
| 277 | -        if( $this->is_valid ) { | |
| 286 | + /** | |
| 287 | + * @hack to avoid the capability validation of the method save_lead for GF 1.9+ | |
| 288 | + */ | |
| 289 | + unset( $_GET['page'] ); | |
| 278 | 290 | |
| 279 | -            do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); | |
| 291 | + GFFormsModel::save_lead( $form, $this->entry ); | |
| 280 | 292 | |
| 281 | - /** | |
| 282 | - * @hack This step is needed to unset the adminOnly from form fields | |
| 283 | - */ | |
| 284 | - $form = $this->form_prepare_for_save(); | |
| 293 | + // If there's a post associated with the entry, process post fields | |
| 294 | +			if( !empty( $this->entry['post_id'] ) ) { | |
| 295 | + $this->maybe_update_post_fields( $form ); | |
| 296 | + } | |
| 285 | 297 | |
| 286 | - /** | |
| 287 | - * @hack to avoid the capability validation of the method save_lead for GF 1.9+ | |
| 288 | - */ | |
| 289 | - unset( $_GET['page'] ); | |
| 298 | + // Perform actions normally performed after updating a lead | |
| 299 | + $this->after_update(); | |
| 290 | 300 | |
| 291 | - GFFormsModel::save_lead( $form, $this->entry ); | |
| 301 | + /** | |
| 302 | + * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry | |
| 303 | + * @param array $form Gravity Forms form array | |
| 304 | + * @param string $entry_id Numeric ID of the entry that was updated | |
| 305 | + */ | |
| 306 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); | |
| 307 | + } | |
| 292 | 308 | |
| 293 | - // If there's a post associated with the entry, process post fields | |
| 294 | -            if( !empty( $this->entry['post_id'] ) ) { | |
| 295 | - $this->maybe_update_post_fields( $form ); | |
| 296 | - } | |
| 309 | + } // process_save | |
| 297 | 310 | |
| 298 | - // Perform actions normally performed after updating a lead | |
| 299 | - $this->after_update(); | |
| 300 | 311 | |
| 301 | - /** | |
| 302 | - * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry | |
| 303 | - * @param array $form Gravity Forms form array | |
| 304 | - * @param string $entry_id Numeric ID of the entry that was updated | |
| 305 | - */ | |
| 306 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); | |
| 307 | - } | |
| 312 | + /** | |
| 313 | + * Have GF handle file uploads | |
| 314 | + * | |
| 315 | + * Copy of code from GFFormDisplay::process_form() | |
| 316 | + * | |
| 317 | + * @param int $form_id | |
| 318 | + */ | |
| 319 | +	function process_save_process_files( $form_id ) { | |
| 308 | 320 | |
| 309 | - } // process_save | |
| 321 | + //Loading files that have been uploaded to temp folder | |
| 322 | + $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); | |
| 323 | +		if ( ! is_array( $files ) ) { | |
| 324 | + $files = array(); | |
| 325 | + } | |
| 310 | 326 | |
| 327 | + RGFormsModel::$uploaded_files[ $form_id ] = $files; | |
| 328 | + } | |
| 311 | 329 | |
| 312 | - /** | |
| 313 | - * Have GF handle file uploads | |
| 314 | - * | |
| 315 | - * Copy of code from GFFormDisplay::process_form() | |
| 316 | - * | |
| 317 | - * @param int $form_id | |
| 318 | - */ | |
| 319 | -    function process_save_process_files( $form_id ) { | |
| 330 | + /** | |
| 331 | + * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView | |
| 332 | + * Late validation done on self::custom_validation | |
| 333 | + * | |
| 334 | + * @param $plupload_init array Plupload settings | |
| 335 | + * @param $form_id | |
| 336 | + * @param $instance | |
| 337 | + * @return mixed | |
| 338 | + */ | |
| 339 | +	public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { | |
| 340 | +		if( ! $this->is_edit_entry() ) { | |
| 341 | + return $plupload_init; | |
| 342 | + } | |
| 320 | 343 | |
| 321 | - //Loading files that have been uploaded to temp folder | |
| 322 | - $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); | |
| 323 | -        if ( ! is_array( $files ) ) { | |
| 324 | - $files = array(); | |
| 325 | - } | |
| 344 | + $plupload_init['gf_vars']['max_files'] = 0; | |
| 326 | 345 | |
| 327 | - RGFormsModel::$uploaded_files[ $form_id ] = $files; | |
| 328 | - } | |
| 346 | + return $plupload_init; | |
| 347 | + } | |
| 329 | 348 | |
| 330 | - /** | |
| 331 | - * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView | |
| 332 | - * Late validation done on self::custom_validation | |
| 333 | - * | |
| 334 | - * @param $plupload_init array Plupload settings | |
| 335 | - * @param $form_id | |
| 336 | - * @param $instance | |
| 337 | - * @return mixed | |
| 338 | - */ | |
| 339 | -    public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { | |
| 340 | -        if( ! $this->is_edit_entry() ) { | |
| 341 | - return $plupload_init; | |
| 342 | - } | |
| 343 | 349 | |
| 344 | - $plupload_init['gf_vars']['max_files'] = 0; | |
| 350 | + /** | |
| 351 | + * Unset adminOnly and convert field input key to string | |
| 352 | + * @return array $form | |
| 353 | + */ | |
| 354 | +	private function form_prepare_for_save() { | |
| 355 | + $form = $this->original_form; | |
| 345 | 356 | |
| 346 | - return $plupload_init; | |
| 347 | - } | |
| 357 | +		foreach( $form['fields'] as &$field ) { | |
| 348 | 358 | |
| 359 | + $field->adminOnly = false; | |
| 349 | 360 | |
| 350 | - /** | |
| 351 | - * Unset adminOnly and convert field input key to string | |
| 352 | - * @return array $form | |
| 353 | - */ | |
| 354 | -    private function form_prepare_for_save() { | |
| 355 | - $form = $this->original_form; | |
| 356 | - | |
| 357 | -        foreach( $form['fields'] as &$field ) { | |
| 361 | +			if( isset( $field->inputs ) && is_array( $field->inputs ) ) { | |
| 362 | +				foreach( $field->inputs as $key => $input ) { | |
| 363 | + $field->inputs[ $key ][ 'id' ] = (string)$input['id']; | |
| 364 | + } | |
| 365 | + } | |
| 366 | + } | |
| 358 | 367 | |
| 359 | - $field->adminOnly = false; | |
| 368 | + return $form; | |
| 369 | + } | |
| 360 | 370 | |
| 361 | -            if( isset( $field->inputs ) && is_array( $field->inputs ) ) { | |
| 362 | -                foreach( $field->inputs as $key => $input ) { | |
| 363 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; | |
| 364 | - } | |
| 365 | - } | |
| 366 | - } | |
| 367 | 371 | |
| 368 | - return $form; | |
| 369 | - } | |
| 372 | + /** | |
| 373 | + * Loop through the fields being edited and if they include Post fields, update the Entry's post object | |
| 374 | + * | |
| 375 | + * @param array $form Gravity Forms form | |
| 376 | + * | |
| 377 | + * @return void | |
| 378 | + */ | |
| 379 | +	function maybe_update_post_fields( $form ) { | |
| 370 | 380 | |
| 381 | + $post_id = $this->entry['post_id']; | |
| 371 | 382 | |
| 372 | - /** | |
| 373 | - * Loop through the fields being edited and if they include Post fields, update the Entry's post object | |
| 374 | - * | |
| 375 | - * @param array $form Gravity Forms form | |
| 376 | - * | |
| 377 | - * @return void | |
| 378 | - */ | |
| 379 | -    function maybe_update_post_fields( $form ) { | |
| 383 | + // Security check | |
| 384 | +		if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { | |
| 385 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); | |
| 386 | + return; | |
| 387 | + } | |
| 380 | 388 | |
| 381 | - $post_id = $this->entry['post_id']; | |
| 382 | - | |
| 383 | - // Security check | |
| 384 | -        if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { | |
| 385 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); | |
| 386 | - return; | |
| 387 | - } | |
| 389 | + $update_entry = false; | |
| 388 | 390 | |
| 389 | - $update_entry = false; | |
| 391 | + $updated_post = $original_post = get_post( $post_id ); | |
| 390 | 392 | |
| 391 | - $updated_post = $original_post = get_post( $post_id ); | |
| 393 | +		foreach ( $this->entry as $field_id => $value ) { | |
| 392 | 394 | |
| 393 | -        foreach ( $this->entry as $field_id => $value ) { | |
| 394 | - | |
| 395 | - //todo: only run through the edit entry configured fields | |
| 395 | + //todo: only run through the edit entry configured fields | |
| 396 | 396 | |
| 397 | - $field = RGFormsModel::get_field( $form, $field_id ); | |
| 397 | + $field = RGFormsModel::get_field( $form, $field_id ); | |
| 398 | 398 | |
| 399 | -            if( class_exists('GF_Fields') ) { | |
| 400 | - $field = GF_Fields::create( $field ); | |
| 401 | - } | |
| 399 | +			if( class_exists('GF_Fields') ) { | |
| 400 | + $field = GF_Fields::create( $field ); | |
| 401 | + } | |
| 402 | 402 | |
| 403 | -            if( GFCommon::is_post_field( $field ) ) { | |
| 403 | +			if( GFCommon::is_post_field( $field ) ) { | |
| 404 | 404 | |
| 405 | - // Get the value of the field, including $_POSTed value | |
| 406 | - $value = RGFormsModel::get_field_value( $field ); | |
| 405 | + // Get the value of the field, including $_POSTed value | |
| 406 | + $value = RGFormsModel::get_field_value( $field ); | |
| 407 | 407 | |
| 408 | -                switch( $field->type ) { | |
| 408 | +				switch( $field->type ) { | |
| 409 | 409 | |
| 410 | - case 'post_title': | |
| 411 | - case 'post_content': | |
| 412 | - case 'post_excerpt': | |
| 413 | -                        $updated_post->{$field->type} = $value; | |
| 414 | - break; | |
| 415 | - case 'post_tags': | |
| 416 | - wp_set_post_tags( $post_id, $value, false ); | |
| 417 | - break; | |
| 418 | - case 'post_category': | |
| 410 | + case 'post_title': | |
| 411 | + case 'post_content': | |
| 412 | + case 'post_excerpt': | |
| 413 | +						$updated_post->{$field->type} = $value; | |
| 414 | + break; | |
| 415 | + case 'post_tags': | |
| 416 | + wp_set_post_tags( $post_id, $value, false ); | |
| 417 | + break; | |
| 418 | + case 'post_category': | |
| 419 | 419 | |
| 420 | - $categories = is_array( $value ) ? array_values( $value ) : (array)$value; | |
| 421 | - $categories = array_filter( $categories ); | |
| 420 | + $categories = is_array( $value ) ? array_values( $value ) : (array)$value; | |
| 421 | + $categories = array_filter( $categories ); | |
| 422 | 422 | |
| 423 | - wp_set_post_categories( $post_id, $categories, false ); | |
| 423 | + wp_set_post_categories( $post_id, $categories, false ); | |
| 424 | 424 | |
| 425 | - // if post_category is type checkbox, then value is an array of inputs | |
| 426 | -                        if( isset( $value[ strval( $field_id ) ] ) ) { | |
| 427 | -                            foreach( $value as $input_id => $val ) { | |
| 428 | - $input_name = 'input_' . str_replace( '.', '_', $input_id ); | |
| 429 | - $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); | |
| 430 | - } | |
| 431 | -                        } else { | |
| 432 | - $input_name = 'input_' . str_replace( '.', '_', $field_id ); | |
| 433 | - $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); | |
| 434 | - } | |
| 425 | + // if post_category is type checkbox, then value is an array of inputs | |
| 426 | +						if( isset( $value[ strval( $field_id ) ] ) ) { | |
| 427 | +							foreach( $value as $input_id => $val ) { | |
| 428 | + $input_name = 'input_' . str_replace( '.', '_', $input_id ); | |
| 429 | + $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] ); | |
| 430 | + } | |
| 431 | +						} else { | |
| 432 | + $input_name = 'input_' . str_replace( '.', '_', $field_id ); | |
| 433 | + $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); | |
| 434 | + } | |
| 435 | 435 | |
| 436 | - break; | |
| 437 | - case 'post_custom_field': | |
| 436 | + break; | |
| 437 | + case 'post_custom_field': | |
| 438 | 438 | |
| 439 | - $input_type = RGFormsModel::get_input_type( $field ); | |
| 440 | - $custom_field_name = $field->postCustomFieldName; | |
| 439 | + $input_type = RGFormsModel::get_input_type( $field ); | |
| 440 | + $custom_field_name = $field->postCustomFieldName; | |
| 441 | 441 | |
| 442 | - // Only certain custom field types are supported | |
| 443 | -                        switch( $input_type ) { | |
| 444 | - case 'fileupload': | |
| 445 | - /** @noinspection PhpMissingBreakStatementInspection */ | |
| 446 | - case 'list': | |
| 447 | -                                if( ! is_string( $value ) ) { | |
| 448 | -                                    $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); | |
| 449 | - } | |
| 450 | - // break; left intentionally out | |
| 451 | - default: | |
| 452 | - update_post_meta( $post_id, $custom_field_name, $value ); | |
| 453 | - } | |
| 442 | + // Only certain custom field types are supported | |
| 443 | +						switch( $input_type ) { | |
| 444 | + case 'fileupload': | |
| 445 | + /** @noinspection PhpMissingBreakStatementInspection */ | |
| 446 | + case 'list': | |
| 447 | +								if( ! is_string( $value ) ) { | |
| 448 | +									$value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); | |
| 449 | + } | |
| 450 | + // break; left intentionally out | |
| 451 | + default: | |
| 452 | + update_post_meta( $post_id, $custom_field_name, $value ); | |
| 453 | + } | |
| 454 | 454 | |
| 455 | - break; | |
| 455 | + break; | |
| 456 | 456 | |
| 457 | - case 'post_image': | |
| 457 | + case 'post_image': | |
| 458 | 458 | |
| 459 | - $input_name = 'input_' . $field_id; | |
| 459 | + $input_name = 'input_' . $field_id; | |
| 460 | 460 | |
| 461 | -                        if ( !empty( $_FILES[ $input_name ]['name'] ) ) { | |
| 461 | +						if ( !empty( $_FILES[ $input_name ]['name'] ) ) { | |
| 462 | 462 | |
| 463 | - // We have a new image | |
| 463 | + // We have a new image | |
| 464 | 464 | |
| 465 | - $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); | |
| 465 | + $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] ); | |
| 466 | 466 | |
| 467 | - // is this field set as featured image, if not, leave | |
| 468 | -                            if ( ! $field->postFeaturedImage ) { | |
| 469 | - break; | |
| 470 | - } | |
| 467 | + // is this field set as featured image, if not, leave | |
| 468 | +							if ( ! $field->postFeaturedImage ) { | |
| 469 | + break; | |
| 470 | + } | |
| 471 | 471 | |
| 472 | - $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); | |
| 473 | - $img_url = rgar( $ary, 0 ); | |
| 472 | + $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); | |
| 473 | + $img_url = rgar( $ary, 0 ); | |
| 474 | 474 | |
| 475 | - $img_title = count( $ary ) > 1 ? $ary[1] : ''; | |
| 476 | - $img_caption = count( $ary ) > 2 ? $ary[2] : ''; | |
| 477 | - $img_description = count( $ary ) > 3 ? $ary[3] : ''; | |
| 475 | + $img_title = count( $ary ) > 1 ? $ary[1] : ''; | |
| 476 | + $img_caption = count( $ary ) > 2 ? $ary[2] : ''; | |
| 477 | + $img_description = count( $ary ) > 3 ? $ary[3] : ''; | |
| 478 | 478 | |
| 479 | - $image_meta = array( | |
| 480 | - 'post_excerpt' => $img_caption, | |
| 481 | - 'post_content' => $img_description, | |
| 482 | - ); | |
| 479 | + $image_meta = array( | |
| 480 | + 'post_excerpt' => $img_caption, | |
| 481 | + 'post_content' => $img_description, | |
| 482 | + ); | |
| 483 | 483 | |
| 484 | - //adding title only if it is not empty. It will default to the file name if it is not in the array | |
| 485 | -                            if ( ! empty( $img_title ) ) { | |
| 486 | - $image_meta['post_title'] = $img_title; | |
| 487 | - } | |
| 484 | + //adding title only if it is not empty. It will default to the file name if it is not in the array | |
| 485 | +							if ( ! empty( $img_title ) ) { | |
| 486 | + $image_meta['post_title'] = $img_title; | |
| 487 | + } | |
| 488 | 488 | |
| 489 | - //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. | |
| 490 | - require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; | |
| 491 | - $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta ); | |
| 489 | + //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. | |
| 490 | + require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; | |
| 491 | + $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta ); | |
| 492 | 492 | |
| 493 | -                            if ( $media_id ) { | |
| 494 | - set_post_thumbnail( $post_id, $media_id ); | |
| 495 | - } | |
| 493 | +							if ( $media_id ) { | |
| 494 | + set_post_thumbnail( $post_id, $media_id ); | |
| 495 | + } | |
| 496 | 496 | |
| 497 | - break; | |
| 497 | + break; | |
| 498 | 498 | |
| 499 | -                        } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { | |
| 499 | +						} elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { | |
| 500 | 500 | |
| 501 | - // Same image although the image title, caption or description might have changed | |
| 501 | + // Same image although the image title, caption or description might have changed | |
| 502 | 502 | |
| 503 | - $ary = ! empty( $this->entry[ $field_id ] ) ? explode( '|:|', $this->entry[ $field_id ] ) : array(); | |
| 504 | - $img_url = rgar( $ary, 0 ); | |
| 503 | + $ary = ! empty( $this->entry[ $field_id ] ) ? explode( '|:|', $this->entry[ $field_id ] ) : array(); | |
| 504 | + $img_url = rgar( $ary, 0 ); | |
| 505 | 505 | |
| 506 | - // is this really the same image or something went wrong ? | |
| 507 | -                            if( $img_url === $_POST[ $input_name ] ) { | |
| 506 | + // is this really the same image or something went wrong ? | |
| 507 | +							if( $img_url === $_POST[ $input_name ] ) { | |
| 508 | 508 | |
| 509 | - $img_title = isset( $value[ $field_id .'.1' ] ) ? $value[ $field_id .'.1' ] : ''; | |
| 510 | - $img_caption = isset( $value[ $field_id .'.4' ] ) ? $value[ $field_id .'.4' ] : ''; | |
| 511 | - $img_description = isset( $value[ $field_id .'.7' ] ) ? $value[ $field_id .'.7' ] : ''; | |
| 509 | + $img_title = isset( $value[ $field_id .'.1' ] ) ? $value[ $field_id .'.1' ] : ''; | |
| 510 | + $img_caption = isset( $value[ $field_id .'.4' ] ) ? $value[ $field_id .'.4' ] : ''; | |
| 511 | + $img_description = isset( $value[ $field_id .'.7' ] ) ? $value[ $field_id .'.7' ] : ''; | |
| 512 | 512 | |
| 513 | - $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; | |
| 513 | + $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; | |
| 514 | 514 | |
| 515 | -                                if ( $field->postFeaturedImage ) { | |
| 515 | +								if ( $field->postFeaturedImage ) { | |
| 516 | 516 | |
| 517 | - $image_meta = array( | |
| 518 | - 'ID' => get_post_thumbnail_id( $post_id ), | |
| 519 | - 'post_title' => $img_title, | |
| 520 | - 'post_excerpt' => $img_caption, | |
| 521 | - 'post_content' => $img_description, | |
| 522 | - ); | |
| 517 | + $image_meta = array( | |
| 518 | + 'ID' => get_post_thumbnail_id( $post_id ), | |
| 519 | + 'post_title' => $img_title, | |
| 520 | + 'post_excerpt' => $img_caption, | |
| 521 | + 'post_content' => $img_description, | |
| 522 | + ); | |
| 523 | 523 | |
| 524 | - // update image title, caption or description | |
| 525 | - wp_update_post( $image_meta ); | |
| 526 | - } | |
| 524 | + // update image title, caption or description | |
| 525 | + wp_update_post( $image_meta ); | |
| 526 | + } | |
| 527 | 527 | |
| 528 | - break; | |
| 529 | - } | |
| 528 | + break; | |
| 529 | + } | |
| 530 | 530 | |
| 531 | - } | |
| 531 | + } | |
| 532 | 532 | |
| 533 | - // if we get here, image was removed or not set. | |
| 533 | + // if we get here, image was removed or not set. | |
| 534 | 534 | |
| 535 | - $value = ''; | |
| 536 | -                        if ( $field->postFeaturedImage ) { | |
| 537 | - delete_post_thumbnail( $post_id ); | |
| 538 | - } | |
| 535 | + $value = ''; | |
| 536 | +						if ( $field->postFeaturedImage ) { | |
| 537 | + delete_post_thumbnail( $post_id ); | |
| 538 | + } | |
| 539 | 539 | |
| 540 | - break; | |
| 540 | + break; | |
| 541 | 541 | |
| 542 | - } | |
| 542 | + } | |
| 543 | 543 | |
| 544 | - //ignore fields that have not changed | |
| 545 | -                if ( $value === rgget( (string) $field_id, $this->entry ) ) { | |
| 546 | - continue; | |
| 547 | - } | |
| 544 | + //ignore fields that have not changed | |
| 545 | +				if ( $value === rgget( (string) $field_id, $this->entry ) ) { | |
| 546 | + continue; | |
| 547 | + } | |
| 548 | 548 | |
| 549 | - // update entry | |
| 550 | -                if( 'post_category' !== $field->type ) { | |
| 551 | - $this->entry[ strval( $field_id ) ] = $value; | |
| 552 | - } | |
| 549 | + // update entry | |
| 550 | +				if( 'post_category' !== $field->type ) { | |
| 551 | + $this->entry[ strval( $field_id ) ] = $value; | |
| 552 | + } | |
| 553 | 553 | |
| 554 | - $update_entry = true; | |
| 554 | + $update_entry = true; | |
| 555 | 555 | |
| 556 | - } | |
| 556 | + } | |
| 557 | 557 | |
| 558 | - } | |
| 558 | + } | |
| 559 | 559 | |
| 560 | -        if( $update_entry ) { | |
| 560 | +		if( $update_entry ) { | |
| 561 | 561 | |
| 562 | - $return_entry = GFAPI::update_entry( $this->entry ); | |
| 562 | + $return_entry = GFAPI::update_entry( $this->entry ); | |
| 563 | 563 | |
| 564 | -            if( is_wp_error( $return_entry ) ) { | |
| 565 | - do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); | |
| 566 | -            } else { | |
| 567 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); | |
| 568 | - } | |
| 564 | +			if( is_wp_error( $return_entry ) ) { | |
| 565 | + do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); | |
| 566 | +			} else { | |
| 567 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); | |
| 568 | + } | |
| 569 | 569 | |
| 570 | - } | |
| 570 | + } | |
| 571 | 571 | |
| 572 | - $return_post = wp_update_post( $updated_post, true ); | |
| 572 | + $return_post = wp_update_post( $updated_post, true ); | |
| 573 | 573 | |
| 574 | -        if( is_wp_error( $return_post ) ) { | |
| 575 | - $return_post->add_data( $updated_post, '$updated_post' ); | |
| 576 | - do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); | |
| 577 | -        } else { | |
| 578 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); | |
| 579 | - } | |
| 574 | +		if( is_wp_error( $return_post ) ) { | |
| 575 | + $return_post->add_data( $updated_post, '$updated_post' ); | |
| 576 | + do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); | |
| 577 | +		} else { | |
| 578 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); | |
| 579 | + } | |
| 580 | 580 | |
| 581 | - } | |
| 581 | + } | |
| 582 | 582 | |
| 583 | 583 | |
| 584 | - /** | |
| 585 | - * Perform actions normally performed after updating a lead | |
| 586 | - * | |
| 587 | - * @since 1.8 | |
| 588 | - * | |
| 589 | - * @see GFEntryDetail::lead_detail_page() | |
| 590 | - * | |
| 591 | - * @return void | |
| 592 | - */ | |
| 593 | -    function after_update() { | |
| 584 | + /** | |
| 585 | + * Perform actions normally performed after updating a lead | |
| 586 | + * | |
| 587 | + * @since 1.8 | |
| 588 | + * | |
| 589 | + * @see GFEntryDetail::lead_detail_page() | |
| 590 | + * | |
| 591 | + * @return void | |
| 592 | + */ | |
| 593 | +	function after_update() { | |
| 594 | 594 | |
| 595 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); | |
| 596 | -        do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); | |
| 595 | + do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); | |
| 596 | +		do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); | |
| 597 | 597 | |
| 598 | - // Re-define the entry now that we've updated it. | |
| 599 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); | |
| 598 | + // Re-define the entry now that we've updated it. | |
| 599 | + $entry = RGFormsModel::get_lead( $this->entry['id'] ); | |
| 600 | 600 | |
| 601 | - $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); | |
| 601 | + $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); | |
| 602 | 602 | |
| 603 | - // We need to clear the cache because Gravity Forms caches the field values, which | |
| 604 | - // we have just updated. | |
| 605 | -        foreach ($this->form['fields'] as $key => $field) { | |
| 606 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); | |
| 607 | - } | |
| 603 | + // We need to clear the cache because Gravity Forms caches the field values, which | |
| 604 | + // we have just updated. | |
| 605 | +		foreach ($this->form['fields'] as $key => $field) { | |
| 606 | + GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); | |
| 607 | + } | |
| 608 | 608 | |
| 609 | - $this->entry = $entry; | |
| 610 | - } | |
| 609 | + $this->entry = $entry; | |
| 610 | + } | |
| 611 | 611 | |
| 612 | 612 | |
| 613 | - /** | |
| 614 | - * Display the Edit Entry form | |
| 615 | - * | |
| 616 | - * @return [type] [description] | |
| 617 | - */ | |
| 618 | -    public function edit_entry_form() { | |
| 613 | + /** | |
| 614 | + * Display the Edit Entry form | |
| 615 | + * | |
| 616 | + * @return [type] [description] | |
| 617 | + */ | |
| 618 | +	public function edit_entry_form() { | |
| 619 | 619 | |
| 620 | - ?> | |
| 620 | + ?> | |
| 621 | 621 | |
| 622 | 622 | <div class="gv-edit-entry-wrapper"><?php | 
| 623 | 623 | |
| 624 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); | |
| 624 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); | |
| 625 | 625 | |
| 626 | - /** | |
| 627 | - * Fixes weird wpautop() issue | |
| 628 | - * @see https://github.com/katzwebservices/GravityView/issues/451 | |
| 629 | - */ | |
| 630 | - echo gravityview_strip_whitespace( $javascript ); | |
| 626 | + /** | |
| 627 | + * Fixes weird wpautop() issue | |
| 628 | + * @see https://github.com/katzwebservices/GravityView/issues/451 | |
| 629 | + */ | |
| 630 | + echo gravityview_strip_whitespace( $javascript ); | |
| 631 | 631 | |
| 632 | - ?><h2 class="gv-edit-entry-title"> | |
| 632 | + ?><h2 class="gv-edit-entry-title"> | |
| 633 | 633 | <span><?php | 
| 634 | 634 | |
| 635 | - /** | |
| 636 | - * @filter `gravityview_edit_entry_title` Modify the edit entry title | |
| 637 | - * @param string $edit_entry_title Modify the "Edit Entry" title | |
| 638 | - * @param GravityView_Edit_Entry_Render $this This object | |
| 639 | - */ | |
| 640 | -                    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); | |
| 635 | + /** | |
| 636 | + * @filter `gravityview_edit_entry_title` Modify the edit entry title | |
| 637 | + * @param string $edit_entry_title Modify the "Edit Entry" title | |
| 638 | + * @param GravityView_Edit_Entry_Render $this This object | |
| 639 | + */ | |
| 640 | +					$edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); | |
| 641 | 641 | |
| 642 | - echo esc_attr( $edit_entry_title ); | |
| 643 | - ?></span> | |
| 642 | + echo esc_attr( $edit_entry_title ); | |
| 643 | + ?></span> | |
| 644 | 644 | </h2> | 
| 645 | 645 | |
| 646 | 646 | <?php $this->maybe_print_message(); ?> | 
| @@ -651,672 +651,672 @@ discard block | ||
| 651 | 651 | |
| 652 | 652 | <?php | 
| 653 | 653 | |
| 654 | - wp_nonce_field( self::$nonce_key, self::$nonce_key ); | |
| 654 | + wp_nonce_field( self::$nonce_key, self::$nonce_key ); | |
| 655 | 655 | |
| 656 | - wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); | |
| 656 | + wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); | |
| 657 | 657 | |
| 658 | - // Print the actual form HTML | |
| 659 | - $this->render_edit_form(); | |
| 658 | + // Print the actual form HTML | |
| 659 | + $this->render_edit_form(); | |
| 660 | 660 | |
| 661 | - ?> | |
| 661 | + ?> | |
| 662 | 662 | </form> | 
| 663 | 663 | |
| 664 | 664 | </div> | 
| 665 | 665 | |
| 666 | 666 | <?php | 
| 667 | - } | |
| 668 | - | |
| 669 | - /** | |
| 670 | - * Display success or error message if the form has been submitted | |
| 671 | - * | |
| 672 | - * @uses GVCommon::generate_notice | |
| 673 | - * | |
| 674 | - * @since TODO | |
| 675 | - * | |
| 676 | - * @return void | |
| 677 | - */ | |
| 678 | -    private function maybe_print_message() { | |
| 679 | - | |
| 680 | -        if( rgpost('action') === 'update' ) { | |
| 681 | - | |
| 682 | - $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); | |
| 683 | - | |
| 684 | -            if( ! $this->is_valid ){ | |
| 685 | - | |
| 686 | - // Keeping this compatible with Gravity Forms. | |
| 687 | -                $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; | |
| 688 | -                $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); | |
| 689 | - | |
| 690 | - echo GVCommon::generate_notice( $message , 'gv-error' ); | |
| 691 | - | |
| 692 | -            } else { | |
| 693 | -                $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); | |
| 694 | - | |
| 695 | - /** | |
| 696 | - * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) | |
| 697 | - * @since 1.5.4 | |
| 698 | - * @param string $entry_updated_message Existing message | |
| 699 | - * @param int $view_id View ID | |
| 700 | - * @param array $entry Gravity Forms entry array | |
| 701 | - * @param string $back_link URL to return to the original entry. @since 1.6 | |
| 702 | - */ | |
| 703 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); | |
| 704 | - | |
| 705 | - echo GVCommon::generate_notice( $message ); | |
| 706 | - } | |
| 707 | - | |
| 708 | - } | |
| 709 | - } | |
| 710 | - | |
| 711 | - /** | |
| 712 | - * Display the Edit Entry form in the original Gravity Forms format | |
| 713 | - * | |
| 714 | - * @since 1.9 | |
| 715 | - * | |
| 716 | - * @param $form | |
| 717 | - * @param $lead | |
| 718 | - * @param $view_id | |
| 719 | - * | |
| 720 | - * @return void | |
| 721 | - */ | |
| 722 | -    private function render_edit_form() { | |
| 723 | - | |
| 724 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); | |
| 725 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); | |
| 726 | - add_filter( 'gform_disable_view_counter', '__return_true' ); | |
| 727 | - | |
| 728 | - add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); | |
| 729 | - add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); | |
| 730 | - | |
| 731 | - // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. | |
| 732 | - unset( $_GET['page'] ); | |
| 733 | - | |
| 734 | - // TODO: Make sure validation isn't handled by GF | |
| 735 | - // TODO: Include CSS for file upload fields | |
| 736 | - // TODO: Verify multiple-page forms | |
| 737 | - // TODO: Product fields are not editable | |
| 738 | - // TODO: Check Updated and Error messages | |
| 739 | - | |
| 740 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); | |
| 741 | - | |
| 742 | - remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); | |
| 743 | - remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); | |
| 744 | - remove_filter( 'gform_disable_view_counter', '__return_true' ); | |
| 745 | - remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); | |
| 746 | - remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); | |
| 747 | - | |
| 748 | - echo $html; | |
| 749 | - } | |
| 750 | - | |
| 751 | - /** | |
| 752 | - * Display the Update/Cancel/Delete buttons for the Edit Entry form | |
| 753 | - * @since 1.8 | |
| 754 | - * @return string | |
| 755 | - */ | |
| 756 | -    public function render_form_buttons() { | |
| 757 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); | |
| 758 | - } | |
| 759 | - | |
| 760 | - | |
| 761 | - /** | |
| 762 | - * Modify the form fields that are shown when using GFFormDisplay::get_form() | |
| 763 | - * | |
| 764 | - * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. | |
| 765 | - * | |
| 766 | - * @param array $form | |
| 767 | - * @param boolean $ajax Whether in AJAX mode | |
| 768 | - * @param array|string $field_values Passed parameters to the form | |
| 769 | - * | |
| 770 | - * @since 1.9 | |
| 771 | - * | |
| 772 | - * @return array Modified form array | |
| 773 | - */ | |
| 774 | -    public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { | |
| 775 | - | |
| 776 | - // In case we have validated the form, use it to inject the validation results into the form render | |
| 777 | -        if( isset( $this->form_after_validation ) ) { | |
| 778 | - $form = $this->form_after_validation; | |
| 779 | -        } else { | |
| 780 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); | |
| 781 | - } | |
| 782 | - | |
| 783 | - $form = $this->filter_conditional_logic( $form ); | |
| 784 | - | |
| 785 | - // for now we don't support Save and Continue feature. | |
| 786 | -        if( ! self::$supports_save_and_continue ) { | |
| 787 | - unset( $form['save'] ); | |
| 788 | - } | |
| 789 | - | |
| 790 | - return $form; | |
| 791 | - } | |
| 792 | - | |
| 793 | - /** | |
| 794 | - * 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. | |
| 795 | - * | |
| 796 | - * @since TODO | |
| 797 | - * | |
| 798 | - * @param string $field_content Always empty. Returning not-empty overrides the input. | |
| 799 | - * @param GF_Field $field | |
| 800 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. | |
| 801 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. | |
| 802 | - * @param int $form_id Form ID | |
| 803 | - * | |
| 804 | - * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next) | |
| 805 | - */ | |
| 806 | -    function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { | |
| 807 | - | |
| 808 | -        if( GFCommon::is_post_field( $field ) ) { | |
| 809 | - | |
| 810 | - $message = null; | |
| 811 | - | |
| 812 | - // First, make sure they have the capability to edit the post. | |
| 813 | -            if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { | |
| 814 | - | |
| 815 | - /** | |
| 816 | - * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post | |
| 817 | - * @param string $message The existing "You don't have permission..." text | |
| 818 | - */ | |
| 819 | -                $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); | |
| 820 | - | |
| 821 | -            } elseif( null === get_post( $this->entry['post_id'] ) ) { | |
| 822 | - /** | |
| 823 | - * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists | |
| 824 | - * @param string $message The existing "This field is not editable; the post no longer exists." text | |
| 825 | - */ | |
| 826 | -                $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); | |
| 827 | - } | |
| 828 | - | |
| 829 | -            if( $message ) { | |
| 830 | -                $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); | |
| 831 | - } | |
| 832 | - } | |
| 833 | - | |
| 834 | - return $field_content; | |
| 835 | - } | |
| 836 | - | |
| 837 | - /** | |
| 838 | - * | |
| 839 | - * Fill-in the saved values into the form inputs | |
| 840 | - * | |
| 841 | - * @param string $field_content Always empty. Returning not-empty overrides the input. | |
| 842 | - * @param GF_Field $field | |
| 843 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. | |
| 844 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. | |
| 845 | - * @param int $form_id Form ID | |
| 846 | - * | |
| 847 | - * @return mixed | |
| 848 | - */ | |
| 849 | -    function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { | |
| 850 | - | |
| 851 | - $gv_field = GravityView_Fields::get_associated_field( $field ); | |
| 852 | - | |
| 853 | - // If the form has been submitted, then we don't need to pre-fill the values, | |
| 854 | - // Except for fileupload type and when a field input is overridden- run always!! | |
| 855 | - if( | |
| 856 | - ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) | |
| 857 | - && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) | |
| 858 | - || ! empty( $field_content ) | |
| 859 | - || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable | |
| 860 | -        ) { | |
| 861 | - return $field_content; | |
| 862 | - } | |
| 863 | - | |
| 864 | - // Turn on Admin-style display for file upload fields only | |
| 865 | -        if( 'fileupload' === $field->type ) { | |
| 866 | - $_GET['page'] = 'gf_entries'; | |
| 867 | - } | |
| 868 | - | |
| 869 | - // SET SOME FIELD DEFAULTS TO PREVENT ISSUES | |
| 870 | - $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ | |
| 871 | - | |
| 872 | - // add categories as choices for Post Category field | |
| 873 | -        if ( 'post_category' === $field->type ) { | |
| 874 | - $field = GFCommon::add_categories_as_choices( $field, $value ); | |
| 875 | - } | |
| 876 | - | |
| 877 | - $field_value = $this->get_field_value( $field ); | |
| 878 | - | |
| 879 | - /** | |
| 880 | - * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed | |
| 881 | - * @since 1.11 | |
| 882 | - * @param mixed $field_value field value used to populate the input | |
| 883 | - * @param object $field Gravity Forms field object ( Class GF_Field ) | |
| 884 | - */ | |
| 885 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); | |
| 886 | - | |
| 887 | - // Prevent any PHP warnings, like undefined index | |
| 888 | - ob_start(); | |
| 889 | - | |
| 890 | -        if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { | |
| 891 | - $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); | |
| 892 | -        } else { | |
| 893 | - $return = $field->get_field_input( $this->form, $field_value, $this->entry ); | |
| 894 | - } | |
| 895 | - | |
| 896 | - | |
| 897 | - // If there was output, it's an error | |
| 898 | - $warnings = ob_get_clean(); | |
| 899 | - | |
| 900 | -	    if( !empty( $warnings ) ) { | |
| 901 | - do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); | |
| 902 | - } | |
| 903 | - | |
| 904 | - /** | |
| 905 | - * Unset hack $_GET['page'] = 'gf_entries' | |
| 906 | - * We need the fileupload html field to render with the proper id | |
| 907 | - * ( <li id="field_80_16" ... > ) | |
| 908 | - */ | |
| 909 | - unset( $_GET['page'] ); | |
| 910 | - | |
| 911 | - return $return; | |
| 912 | - } | |
| 913 | - | |
| 914 | - /** | |
| 915 | - * Modify the value for the current field input | |
| 916 | - * | |
| 917 | - * @param GF_Field $field | |
| 918 | - * | |
| 919 | - * @return array|mixed|string|void | |
| 920 | - */ | |
| 921 | -    private function get_field_value( $field ) { | |
| 922 | - | |
| 923 | - /** | |
| 924 | - * @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. | |
| 925 | - * @param boolean True: override saved values; False: don't override (default) | |
| 926 | - * @param $field GF_Field object Gravity Forms field object | |
| 927 | - * @since 1.13 | |
| 928 | - */ | |
| 929 | - $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); | |
| 930 | - | |
| 931 | - // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) | |
| 932 | -        if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { | |
| 933 | - | |
| 934 | - $field_value = array(); | |
| 935 | - | |
| 936 | - // only accept pre-populated values if the field doesn't have any choice selected. | |
| 937 | - $allow_pre_populated = $field->allowsPrepopulate; | |
| 938 | - | |
| 939 | -            foreach ( (array)$field->inputs as $input ) { | |
| 940 | - | |
| 941 | - $input_id = strval( $input['id'] ); | |
| 667 | + } | |
| 668 | + | |
| 669 | + /** | |
| 670 | + * Display success or error message if the form has been submitted | |
| 671 | + * | |
| 672 | + * @uses GVCommon::generate_notice | |
| 673 | + * | |
| 674 | + * @since TODO | |
| 675 | + * | |
| 676 | + * @return void | |
| 677 | + */ | |
| 678 | +	private function maybe_print_message() { | |
| 679 | + | |
| 680 | +		if( rgpost('action') === 'update' ) { | |
| 681 | + | |
| 682 | + $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); | |
| 683 | + | |
| 684 | +			if( ! $this->is_valid ){ | |
| 685 | + | |
| 686 | + // Keeping this compatible with Gravity Forms. | |
| 687 | +				$validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; | |
| 688 | +				$message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); | |
| 689 | + | |
| 690 | + echo GVCommon::generate_notice( $message , 'gv-error' ); | |
| 691 | + | |
| 692 | +			} else { | |
| 693 | +				$entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); | |
| 694 | + | |
| 695 | + /** | |
| 696 | + * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) | |
| 697 | + * @since 1.5.4 | |
| 698 | + * @param string $entry_updated_message Existing message | |
| 699 | + * @param int $view_id View ID | |
| 700 | + * @param array $entry Gravity Forms entry array | |
| 701 | + * @param string $back_link URL to return to the original entry. @since 1.6 | |
| 702 | + */ | |
| 703 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); | |
| 704 | + | |
| 705 | + echo GVCommon::generate_notice( $message ); | |
| 706 | + } | |
| 707 | + | |
| 708 | + } | |
| 709 | + } | |
| 710 | + | |
| 711 | + /** | |
| 712 | + * Display the Edit Entry form in the original Gravity Forms format | |
| 713 | + * | |
| 714 | + * @since 1.9 | |
| 715 | + * | |
| 716 | + * @param $form | |
| 717 | + * @param $lead | |
| 718 | + * @param $view_id | |
| 719 | + * | |
| 720 | + * @return void | |
| 721 | + */ | |
| 722 | +	private function render_edit_form() { | |
| 723 | + | |
| 724 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); | |
| 725 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); | |
| 726 | + add_filter( 'gform_disable_view_counter', '__return_true' ); | |
| 727 | + | |
| 728 | + add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); | |
| 729 | + add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); | |
| 730 | + | |
| 731 | + // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. | |
| 732 | + unset( $_GET['page'] ); | |
| 733 | + | |
| 734 | + // TODO: Make sure validation isn't handled by GF | |
| 735 | + // TODO: Include CSS for file upload fields | |
| 736 | + // TODO: Verify multiple-page forms | |
| 737 | + // TODO: Product fields are not editable | |
| 738 | + // TODO: Check Updated and Error messages | |
| 739 | + | |
| 740 | + $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); | |
| 741 | + | |
| 742 | + remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); | |
| 743 | + remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); | |
| 744 | + remove_filter( 'gform_disable_view_counter', '__return_true' ); | |
| 745 | + remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); | |
| 746 | + remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); | |
| 747 | + | |
| 748 | + echo $html; | |
| 749 | + } | |
| 750 | + | |
| 751 | + /** | |
| 752 | + * Display the Update/Cancel/Delete buttons for the Edit Entry form | |
| 753 | + * @since 1.8 | |
| 754 | + * @return string | |
| 755 | + */ | |
| 756 | +	public function render_form_buttons() { | |
| 757 | + return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); | |
| 758 | + } | |
| 759 | + | |
| 760 | + | |
| 761 | + /** | |
| 762 | + * Modify the form fields that are shown when using GFFormDisplay::get_form() | |
| 763 | + * | |
| 764 | + * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. | |
| 765 | + * | |
| 766 | + * @param array $form | |
| 767 | + * @param boolean $ajax Whether in AJAX mode | |
| 768 | + * @param array|string $field_values Passed parameters to the form | |
| 769 | + * | |
| 770 | + * @since 1.9 | |
| 771 | + * | |
| 772 | + * @return array Modified form array | |
| 773 | + */ | |
| 774 | +	public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { | |
| 775 | + | |
| 776 | + // In case we have validated the form, use it to inject the validation results into the form render | |
| 777 | +		if( isset( $this->form_after_validation ) ) { | |
| 778 | + $form = $this->form_after_validation; | |
| 779 | +		} else { | |
| 780 | + $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); | |
| 781 | + } | |
| 782 | + | |
| 783 | + $form = $this->filter_conditional_logic( $form ); | |
| 784 | + | |
| 785 | + // for now we don't support Save and Continue feature. | |
| 786 | +		if( ! self::$supports_save_and_continue ) { | |
| 787 | + unset( $form['save'] ); | |
| 788 | + } | |
| 789 | + | |
| 790 | + return $form; | |
| 791 | + } | |
| 792 | + | |
| 793 | + /** | |
| 794 | + * 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. | |
| 795 | + * | |
| 796 | + * @since TODO | |
| 797 | + * | |
| 798 | + * @param string $field_content Always empty. Returning not-empty overrides the input. | |
| 799 | + * @param GF_Field $field | |
| 800 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. | |
| 801 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. | |
| 802 | + * @param int $form_id Form ID | |
| 803 | + * | |
| 804 | + * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next) | |
| 805 | + */ | |
| 806 | +	function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { | |
| 807 | + | |
| 808 | +		if( GFCommon::is_post_field( $field ) ) { | |
| 809 | + | |
| 810 | + $message = null; | |
| 811 | + | |
| 812 | + // First, make sure they have the capability to edit the post. | |
| 813 | +			if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { | |
| 814 | + | |
| 815 | + /** | |
| 816 | + * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post | |
| 817 | + * @param string $message The existing "You don't have permission..." text | |
| 818 | + */ | |
| 819 | +				$message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); | |
| 820 | + | |
| 821 | +			} elseif( null === get_post( $this->entry['post_id'] ) ) { | |
| 822 | + /** | |
| 823 | + * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists | |
| 824 | + * @param string $message The existing "This field is not editable; the post no longer exists." text | |
| 825 | + */ | |
| 826 | +				$message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); | |
| 827 | + } | |
| 828 | + | |
| 829 | +			if( $message ) { | |
| 830 | +				$field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); | |
| 831 | + } | |
| 832 | + } | |
| 833 | + | |
| 834 | + return $field_content; | |
| 835 | + } | |
| 836 | + | |
| 837 | + /** | |
| 838 | + * | |
| 839 | + * Fill-in the saved values into the form inputs | |
| 840 | + * | |
| 841 | + * @param string $field_content Always empty. Returning not-empty overrides the input. | |
| 842 | + * @param GF_Field $field | |
| 843 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. | |
| 844 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. | |
| 845 | + * @param int $form_id Form ID | |
| 846 | + * | |
| 847 | + * @return mixed | |
| 848 | + */ | |
| 849 | +	function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { | |
| 850 | + | |
| 851 | + $gv_field = GravityView_Fields::get_associated_field( $field ); | |
| 852 | + | |
| 853 | + // If the form has been submitted, then we don't need to pre-fill the values, | |
| 854 | + // Except for fileupload type and when a field input is overridden- run always!! | |
| 855 | + if( | |
| 856 | + ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) | |
| 857 | + && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) | |
| 858 | + || ! empty( $field_content ) | |
| 859 | + || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable | |
| 860 | +		) { | |
| 861 | + return $field_content; | |
| 862 | + } | |
| 863 | + | |
| 864 | + // Turn on Admin-style display for file upload fields only | |
| 865 | +		if( 'fileupload' === $field->type ) { | |
| 866 | + $_GET['page'] = 'gf_entries'; | |
| 867 | + } | |
| 868 | + | |
| 869 | + // SET SOME FIELD DEFAULTS TO PREVENT ISSUES | |
| 870 | + $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ | |
| 871 | + | |
| 872 | + // add categories as choices for Post Category field | |
| 873 | +		if ( 'post_category' === $field->type ) { | |
| 874 | + $field = GFCommon::add_categories_as_choices( $field, $value ); | |
| 875 | + } | |
| 876 | + | |
| 877 | + $field_value = $this->get_field_value( $field ); | |
| 878 | + | |
| 879 | + /** | |
| 880 | + * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed | |
| 881 | + * @since 1.11 | |
| 882 | + * @param mixed $field_value field value used to populate the input | |
| 883 | + * @param object $field Gravity Forms field object ( Class GF_Field ) | |
| 884 | + */ | |
| 885 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); | |
| 886 | + | |
| 887 | + // Prevent any PHP warnings, like undefined index | |
| 888 | + ob_start(); | |
| 889 | + | |
| 890 | +		if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { | |
| 891 | + $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); | |
| 892 | +		} else { | |
| 893 | + $return = $field->get_field_input( $this->form, $field_value, $this->entry ); | |
| 894 | + } | |
| 895 | + | |
| 896 | + | |
| 897 | + // If there was output, it's an error | |
| 898 | + $warnings = ob_get_clean(); | |
| 899 | + | |
| 900 | +		if( !empty( $warnings ) ) { | |
| 901 | + do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); | |
| 902 | + } | |
| 903 | + | |
| 904 | + /** | |
| 905 | + * Unset hack $_GET['page'] = 'gf_entries' | |
| 906 | + * We need the fileupload html field to render with the proper id | |
| 907 | + * ( <li id="field_80_16" ... > ) | |
| 908 | + */ | |
| 909 | + unset( $_GET['page'] ); | |
| 910 | + | |
| 911 | + return $return; | |
| 912 | + } | |
| 913 | + | |
| 914 | + /** | |
| 915 | + * Modify the value for the current field input | |
| 916 | + * | |
| 917 | + * @param GF_Field $field | |
| 918 | + * | |
| 919 | + * @return array|mixed|string|void | |
| 920 | + */ | |
| 921 | +	private function get_field_value( $field ) { | |
| 922 | + | |
| 923 | + /** | |
| 924 | + * @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. | |
| 925 | + * @param boolean True: override saved values; False: don't override (default) | |
| 926 | + * @param $field GF_Field object Gravity Forms field object | |
| 927 | + * @since 1.13 | |
| 928 | + */ | |
| 929 | + $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); | |
| 930 | + | |
| 931 | + // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) | |
| 932 | +		if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { | |
| 933 | + | |
| 934 | + $field_value = array(); | |
| 935 | + | |
| 936 | + // only accept pre-populated values if the field doesn't have any choice selected. | |
| 937 | + $allow_pre_populated = $field->allowsPrepopulate; | |
| 938 | + | |
| 939 | +			foreach ( (array)$field->inputs as $input ) { | |
| 940 | + | |
| 941 | + $input_id = strval( $input['id'] ); | |
| 942 | 942 | |
| 943 | -                if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { | |
| 944 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; | |
| 945 | - $allow_pre_populated = false; | |
| 946 | - } | |
| 943 | +				if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { | |
| 944 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; | |
| 945 | + $allow_pre_populated = false; | |
| 946 | + } | |
| 947 | 947 | |
| 948 | - } | |
| 948 | + } | |
| 949 | 949 | |
| 950 | - $pre_value = $field->get_value_submission( array(), false ); | |
| 950 | + $pre_value = $field->get_value_submission( array(), false ); | |
| 951 | 951 | |
| 952 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; | |
| 952 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; | |
| 953 | 953 | |
| 954 | -        } else { | |
| 954 | +		} else { | |
| 955 | 955 | |
| 956 | - $id = intval( $field->id ); | |
| 956 | + $id = intval( $field->id ); | |
| 957 | 957 | |
| 958 | - // get pre-populated value if exists | |
| 959 | - $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; | |
| 958 | + // get pre-populated value if exists | |
| 959 | + $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; | |
| 960 | 960 | |
| 961 | - // saved field entry value (if empty, fallback to the pre-populated value, if exists) | |
| 962 | - // or pre-populated value if not empty and set to override saved value | |
| 963 | - $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; | |
| 961 | + // saved field entry value (if empty, fallback to the pre-populated value, if exists) | |
| 962 | + // or pre-populated value if not empty and set to override saved value | |
| 963 | + $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; | |
| 964 | 964 | |
| 965 | - // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. | |
| 966 | -            if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { | |
| 967 | - $categories = array(); | |
| 968 | -                foreach ( explode( ',', $field_value ) as $cat_string ) { | |
| 969 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); | |
| 970 | - } | |
| 971 | - $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); | |
| 972 | - } | |
| 965 | + // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. | |
| 966 | +			if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { | |
| 967 | + $categories = array(); | |
| 968 | +				foreach ( explode( ',', $field_value ) as $cat_string ) { | |
| 969 | + $categories[] = GFCommon::format_post_category( $cat_string, true ); | |
| 970 | + } | |
| 971 | + $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); | |
| 972 | + } | |
| 973 | 973 | |
| 974 | - } | |
| 974 | + } | |
| 975 | 975 | |
| 976 | - // if value is empty get the default value if defined | |
| 977 | - $field_value = $field->get_value_default_if_empty( $field_value ); | |
| 976 | + // if value is empty get the default value if defined | |
| 977 | + $field_value = $field->get_value_default_if_empty( $field_value ); | |
| 978 | 978 | |
| 979 | - return $field_value; | |
| 980 | - } | |
| 979 | + return $field_value; | |
| 980 | + } | |
| 981 | 981 | |
| 982 | 982 | |
| 983 | - // ---- Entry validation | |
| 983 | + // ---- Entry validation | |
| 984 | 984 | |
| 985 | - /** | |
| 986 | - * Add field keys that Gravity Forms expects. | |
| 987 | - * | |
| 988 | - * @see GFFormDisplay::validate() | |
| 989 | - * @param array $form GF Form | |
| 990 | - * @return array Modified GF Form | |
| 991 | - */ | |
| 992 | -    function gform_pre_validation( $form ) { | |
| 985 | + /** | |
| 986 | + * Add field keys that Gravity Forms expects. | |
| 987 | + * | |
| 988 | + * @see GFFormDisplay::validate() | |
| 989 | + * @param array $form GF Form | |
| 990 | + * @return array Modified GF Form | |
| 991 | + */ | |
| 992 | +	function gform_pre_validation( $form ) { | |
| 993 | 993 | |
| 994 | -        if( ! $this->verify_nonce() ) { | |
| 995 | - return $form; | |
| 996 | - } | |
| 994 | +		if( ! $this->verify_nonce() ) { | |
| 995 | + return $form; | |
| 996 | + } | |
| 997 | 997 | |
| 998 | - // Fix PHP warning regarding undefined index. | |
| 999 | -        foreach ( $form['fields'] as &$field) { | |
| 998 | + // Fix PHP warning regarding undefined index. | |
| 999 | +		foreach ( $form['fields'] as &$field) { | |
| 1000 | 1000 | |
| 1001 | - // This is because we're doing admin form pretending to be front-end, so Gravity Forms | |
| 1002 | - // expects certain field array items to be set. | |
| 1003 | -            foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { | |
| 1004 | -	            $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; | |
| 1005 | - } | |
| 1001 | + // This is because we're doing admin form pretending to be front-end, so Gravity Forms | |
| 1002 | + // expects certain field array items to be set. | |
| 1003 | +			foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { | |
| 1004 | +				$field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; | |
| 1005 | + } | |
| 1006 | 1006 | |
| 1007 | - // unset emailConfirmEnabled for email type fields | |
| 1008 | -           /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { | |
| 1007 | + // unset emailConfirmEnabled for email type fields | |
| 1008 | +		   /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { | |
| 1009 | 1009 | $field['emailConfirmEnabled'] = ''; | 
| 1010 | 1010 | }*/ | 
| 1011 | 1011 | |
| 1012 | -            switch( RGFormsModel::get_input_type( $field ) ) { | |
| 1012 | +			switch( RGFormsModel::get_input_type( $field ) ) { | |
| 1013 | 1013 | |
| 1014 | - /** | |
| 1015 | - * 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. | |
| 1016 | - * | |
| 1017 | - * 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. | |
| 1018 | - * | |
| 1019 | - * @hack | |
| 1020 | - */ | |
| 1021 | - case 'fileupload': | |
| 1022 | - | |
| 1023 | - // Set the previous value | |
| 1024 | - $entry = $this->get_entry(); | |
| 1025 | - | |
| 1026 | - $input_name = 'input_'.$field->id; | |
| 1027 | - $form_id = $form['id']; | |
| 1028 | - | |
| 1029 | - $value = NULL; | |
| 1030 | - | |
| 1031 | - // Use the previous entry value as the default. | |
| 1032 | -                    if( isset( $entry[ $field->id ] ) ) { | |
| 1033 | - $value = $entry[ $field->id ]; | |
| 1034 | - } | |
| 1014 | + /** | |
| 1015 | + * 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. | |
| 1016 | + * | |
| 1017 | + * 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. | |
| 1018 | + * | |
| 1019 | + * @hack | |
| 1020 | + */ | |
| 1021 | + case 'fileupload': | |
| 1035 | 1022 | |
| 1036 | - // If this is a single upload file | |
| 1037 | -                    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { | |
| 1038 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); | |
| 1039 | - $value = $file_path['url']; | |
| 1023 | + // Set the previous value | |
| 1024 | + $entry = $this->get_entry(); | |
| 1040 | 1025 | |
| 1041 | -                    } else { | |
| 1042 | - | |
| 1043 | - // Fix PHP warning on line 1498 of form_display.php for post_image fields | |
| 1044 | - // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 | |
| 1045 | -                        $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); | |
| 1046 | - | |
| 1047 | - } | |
| 1048 | - | |
| 1049 | -                    if( rgar($field, "multipleFiles") ) { | |
| 1050 | - | |
| 1051 | - // If there are fresh uploads, process and merge them. | |
| 1052 | - // Otherwise, use the passed values, which should be json-encoded array of URLs | |
| 1053 | -                        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { | |
| 1054 | - $value = empty( $value ) ? '[]' : $value; | |
| 1055 | - $value = stripslashes_deep( $value ); | |
| 1056 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); | |
| 1057 | - } | |
| 1026 | + $input_name = 'input_'.$field->id; | |
| 1027 | + $form_id = $form['id']; | |
| 1058 | 1028 | |
| 1059 | -                    } else { | |
| 1029 | + $value = NULL; | |
| 1060 | 1030 | |
| 1061 | - // A file already exists when editing an entry | |
| 1062 | - // We set this to solve issue when file upload fields are required. | |
| 1063 | - GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; | |
| 1031 | + // Use the previous entry value as the default. | |
| 1032 | +					if( isset( $entry[ $field->id ] ) ) { | |
| 1033 | + $value = $entry[ $field->id ]; | |
| 1034 | + } | |
| 1064 | 1035 | |
| 1065 | - } | |
| 1036 | + // If this is a single upload file | |
| 1037 | +					if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { | |
| 1038 | + $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); | |
| 1039 | + $value = $file_path['url']; | |
| 1066 | 1040 | |
| 1067 | - $this->entry[ $input_name ] = $value; | |
| 1068 | - $_POST[ $input_name ] = $value; | |
| 1041 | +					} else { | |
| 1069 | 1042 | |
| 1070 | - break; | |
| 1043 | + // Fix PHP warning on line 1498 of form_display.php for post_image fields | |
| 1044 | + // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 | |
| 1045 | +						$_FILES[ $input_name ] = array('name' => '', 'size' => '' ); | |
| 1071 | 1046 | |
| 1072 | - case 'number': | |
| 1073 | - // Fix "undefined index" issue at line 1286 in form_display.php | |
| 1074 | -                    if( !isset( $_POST['input_'.$field->id ] ) ) { | |
| 1075 | - $_POST['input_'.$field->id ] = NULL; | |
| 1076 | - } | |
| 1077 | - break; | |
| 1078 | - case 'captcha': | |
| 1079 | - // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php | |
| 1080 | - $_POST['recaptcha_challenge_field'] = NULL; | |
| 1081 | - $_POST['recaptcha_response_field'] = NULL; | |
| 1082 | - break; | |
| 1083 | - } | |
| 1047 | + } | |
| 1084 | 1048 | |
| 1085 | - } | |
| 1049 | +					if( rgar($field, "multipleFiles") ) { | |
| 1086 | 1050 | |
| 1087 | - return $form; | |
| 1088 | - } | |
| 1051 | + // If there are fresh uploads, process and merge them. | |
| 1052 | + // Otherwise, use the passed values, which should be json-encoded array of URLs | |
| 1053 | +						if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { | |
| 1054 | + $value = empty( $value ) ? '[]' : $value; | |
| 1055 | + $value = stripslashes_deep( $value ); | |
| 1056 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); | |
| 1057 | + } | |
| 1089 | 1058 | |
| 1059 | +					} else { | |
| 1090 | 1060 | |
| 1091 | - /** | |
| 1092 | - * Process validation for a edit entry submission | |
| 1093 | - * | |
| 1094 | - * Sets the `is_valid` object var | |
| 1095 | - * | |
| 1096 | - * @return void | |
| 1097 | - */ | |
| 1098 | -    function validate() { | |
| 1061 | + // A file already exists when editing an entry | |
| 1062 | + // We set this to solve issue when file upload fields are required. | |
| 1063 | + GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; | |
| 1099 | 1064 | |
| 1100 | - /** | |
| 1101 | - * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry | |
| 1102 | - * GF User Registration Add-on version > 3.x has a different class name | |
| 1103 | - * @since 1.16.2 | |
| 1104 | - */ | |
| 1105 | -        if ( class_exists( 'GF_User_Registration' ) ) { | |
| 1106 | - remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) ); | |
| 1107 | -        } else  if ( class_exists( 'GFUser' ) ) { | |
| 1108 | - remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); | |
| 1109 | - } | |
| 1065 | + } | |
| 1110 | 1066 | |
| 1067 | + $this->entry[ $input_name ] = $value; | |
| 1068 | + $_POST[ $input_name ] = $value; | |
| 1111 | 1069 | |
| 1112 | - /** | |
| 1113 | - * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. | |
| 1114 | - * You can enter whatever you want! | |
| 1115 | - * We try validating, and customize the results using `self::custom_validation()` | |
| 1116 | - */ | |
| 1117 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); | |
| 1070 | + break; | |
| 1118 | 1071 | |
| 1119 | - // Needed by the validate funtion | |
| 1120 | - $failed_validation_page = NULL; | |
| 1121 | - $field_values = RGForms::post( 'gform_field_values' ); | |
| 1072 | + case 'number': | |
| 1073 | + // Fix "undefined index" issue at line 1286 in form_display.php | |
| 1074 | +					if( !isset( $_POST['input_'.$field->id ] ) ) { | |
| 1075 | + $_POST['input_'.$field->id ] = NULL; | |
| 1076 | + } | |
| 1077 | + break; | |
| 1078 | + case 'captcha': | |
| 1079 | + // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php | |
| 1080 | + $_POST['recaptcha_challenge_field'] = NULL; | |
| 1081 | + $_POST['recaptcha_response_field'] = NULL; | |
| 1082 | + break; | |
| 1083 | + } | |
| 1122 | 1084 | |
| 1123 | - // Prevent entry limit from running when editing an entry, also | |
| 1124 | - // prevent form scheduling from preventing editing | |
| 1125 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); | |
| 1085 | + } | |
| 1126 | 1086 | |
| 1127 | - // Hide fields depending on Edit Entry settings | |
| 1128 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); | |
| 1087 | + return $form; | |
| 1088 | + } | |
| 1129 | 1089 | |
| 1130 | - $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); | |
| 1131 | 1090 | |
| 1132 | - remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); | |
| 1133 | - } | |
| 1091 | + /** | |
| 1092 | + * Process validation for a edit entry submission | |
| 1093 | + * | |
| 1094 | + * Sets the `is_valid` object var | |
| 1095 | + * | |
| 1096 | + * @return void | |
| 1097 | + */ | |
| 1098 | +	function validate() { | |
| 1099 | + | |
| 1100 | + /** | |
| 1101 | + * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry | |
| 1102 | + * GF User Registration Add-on version > 3.x has a different class name | |
| 1103 | + * @since 1.16.2 | |
| 1104 | + */ | |
| 1105 | +		if ( class_exists( 'GF_User_Registration' ) ) { | |
| 1106 | + remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) ); | |
| 1107 | +		} else  if ( class_exists( 'GFUser' ) ) { | |
| 1108 | + remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); | |
| 1109 | + } | |
| 1134 | 1110 | |
| 1135 | 1111 | |
| 1136 | - /** | |
| 1137 | - * Make validation work for Edit Entry | |
| 1138 | - * | |
| 1139 | - * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end | |
| 1140 | - * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post | |
| 1141 | - * fields. This goes through all the fields and if they're an invalid post field, we | |
| 1142 | - * set them as valid. If there are still issues, we'll return false. | |
| 1143 | - * | |
| 1144 | - * @param [type] $validation_results [description] | |
| 1145 | - * @return [type] [description] | |
| 1146 | - */ | |
| 1147 | -    function custom_validation( $validation_results ) { | |
| 1112 | + /** | |
| 1113 | + * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. | |
| 1114 | + * You can enter whatever you want! | |
| 1115 | + * We try validating, and customize the results using `self::custom_validation()` | |
| 1116 | + */ | |
| 1117 | + add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); | |
| 1148 | 1118 | |
| 1149 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); | |
| 1119 | + // Needed by the validate funtion | |
| 1120 | + $failed_validation_page = NULL; | |
| 1121 | + $field_values = RGForms::post( 'gform_field_values' ); | |
| 1150 | 1122 | |
| 1151 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 1123 | + // Prevent entry limit from running when editing an entry, also | |
| 1124 | + // prevent form scheduling from preventing editing | |
| 1125 | + unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); | |
| 1152 | 1126 | |
| 1153 | - $gv_valid = true; | |
| 1127 | + // Hide fields depending on Edit Entry settings | |
| 1128 | + $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); | |
| 1154 | 1129 | |
| 1155 | -        foreach ( $validation_results['form']['fields'] as $key => &$field ) { | |
| 1130 | + $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); | |
| 1156 | 1131 | |
| 1157 | - $value = RGFormsModel::get_field_value( $field ); | |
| 1158 | - $field_type = RGFormsModel::get_input_type( $field ); | |
| 1132 | + remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); | |
| 1133 | + } | |
| 1159 | 1134 | |
| 1160 | - // Validate always | |
| 1161 | -            switch ( $field_type ) { | |
| 1162 | 1135 | |
| 1136 | + /** | |
| 1137 | + * Make validation work for Edit Entry | |
| 1138 | + * | |
| 1139 | + * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end | |
| 1140 | + * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post | |
| 1141 | + * fields. This goes through all the fields and if they're an invalid post field, we | |
| 1142 | + * set them as valid. If there are still issues, we'll return false. | |
| 1143 | + * | |
| 1144 | + * @param [type] $validation_results [description] | |
| 1145 | + * @return [type] [description] | |
| 1146 | + */ | |
| 1147 | +	function custom_validation( $validation_results ) { | |
| 1163 | 1148 | |
| 1164 | - case 'fileupload' : | |
| 1165 | - case 'post_image': | |
| 1149 | +		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); | |
| 1166 | 1150 | |
| 1167 | - // in case nothing is uploaded but there are already files saved | |
| 1168 | -                    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { | |
| 1169 | - $field->failed_validation = false; | |
| 1170 | - unset( $field->validation_message ); | |
| 1171 | - } | |
| 1151 | +		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); | |
| 1172 | 1152 | |
| 1173 | - // validate if multi file upload reached max number of files [maxFiles] => 2 | |
| 1174 | -                    if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { | |
| 1153 | + $gv_valid = true; | |
| 1175 | 1154 | |
| 1176 | - $input_name = 'input_' . $field->id; | |
| 1177 | - //uploaded | |
| 1178 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); | |
| 1155 | +		foreach ( $validation_results['form']['fields'] as $key => &$field ) { | |
| 1179 | 1156 | |
| 1180 | - //existent | |
| 1181 | - $entry = $this->get_entry(); | |
| 1182 | - $value = NULL; | |
| 1183 | -                        if( isset( $entry[ $field->id ] ) ) { | |
| 1184 | - $value = json_decode( $entry[ $field->id ], true ); | |
| 1185 | - } | |
| 1157 | + $value = RGFormsModel::get_field_value( $field ); | |
| 1158 | + $field_type = RGFormsModel::get_input_type( $field ); | |
| 1186 | 1159 | |
| 1187 | - // count uploaded files and existent entry files | |
| 1188 | - $count_files = count( $file_names ) + count( $value ); | |
| 1160 | + // Validate always | |
| 1161 | +			switch ( $field_type ) { | |
| 1189 | 1162 | |
| 1190 | -                        if( $count_files > $field->maxFiles ) { | |
| 1191 | - $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); | |
| 1192 | - $field->failed_validation = 1; | |
| 1193 | - $gv_valid = false; | |
| 1194 | 1163 | |
| 1195 | - // in case of error make sure the newest upload files are removed from the upload input | |
| 1196 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; | |
| 1197 | - } | |
| 1164 | + case 'fileupload' : | |
| 1165 | + case 'post_image': | |
| 1198 | 1166 | |
| 1199 | - } | |
| 1167 | + // in case nothing is uploaded but there are already files saved | |
| 1168 | +					if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { | |
| 1169 | + $field->failed_validation = false; | |
| 1170 | + unset( $field->validation_message ); | |
| 1171 | + } | |
| 1200 | 1172 | |
| 1173 | + // validate if multi file upload reached max number of files [maxFiles] => 2 | |
| 1174 | +					if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { | |
| 1201 | 1175 | |
| 1202 | - break; | |
| 1176 | + $input_name = 'input_' . $field->id; | |
| 1177 | + //uploaded | |
| 1178 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); | |
| 1203 | 1179 | |
| 1204 | - } | |
| 1180 | + //existent | |
| 1181 | + $entry = $this->get_entry(); | |
| 1182 | + $value = NULL; | |
| 1183 | +						if( isset( $entry[ $field->id ] ) ) { | |
| 1184 | + $value = json_decode( $entry[ $field->id ], true ); | |
| 1185 | + } | |
| 1205 | 1186 | |
| 1206 | - // This field has failed validation. | |
| 1207 | -            if( !empty( $field->failed_validation ) ) { | |
| 1187 | + // count uploaded files and existent entry files | |
| 1188 | + $count_files = count( $file_names ) + count( $value ); | |
| 1208 | 1189 | |
| 1209 | - do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); | |
| 1190 | +						if( $count_files > $field->maxFiles ) { | |
| 1191 | + $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); | |
| 1192 | + $field->failed_validation = 1; | |
| 1193 | + $gv_valid = false; | |
| 1210 | 1194 | |
| 1211 | -                switch ( $field_type ) { | |
| 1195 | + // in case of error make sure the newest upload files are removed from the upload input | |
| 1196 | + GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; | |
| 1197 | + } | |
| 1212 | 1198 | |
| 1213 | - // Captchas don't need to be re-entered. | |
| 1214 | - case 'captcha': | |
| 1199 | + } | |
| 1215 | 1200 | |
| 1216 | - // Post Image fields aren't editable, so we un-fail them. | |
| 1217 | - case 'post_image': | |
| 1218 | - $field->failed_validation = false; | |
| 1219 | - unset( $field->validation_message ); | |
| 1220 | - break; | |
| 1221 | 1201 | |
| 1222 | - } | |
| 1202 | + break; | |
| 1223 | 1203 | |
| 1224 | - // You can't continue inside a switch, so we do it after. | |
| 1225 | -                if( empty( $field->failed_validation ) ) { | |
| 1226 | - continue; | |
| 1227 | - } | |
| 1204 | + } | |
| 1228 | 1205 | |
| 1229 | - // checks if the No Duplicates option is not validating entry against itself, since | |
| 1230 | - // we're editing a stored entry, it would also assume it's a duplicate. | |
| 1231 | -                if( !empty( $field->noDuplicates ) ) { | |
| 1206 | + // This field has failed validation. | |
| 1207 | +			if( !empty( $field->failed_validation ) ) { | |
| 1232 | 1208 | |
| 1233 | - $entry = $this->get_entry(); | |
| 1209 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); | |
| 1234 | 1210 | |
| 1235 | - // If the value of the entry is the same as the stored value | |
| 1236 | - // Then we can assume it's not a duplicate, it's the same. | |
| 1237 | -                    if( !empty( $entry ) && $value == $entry[ $field->id ] ) { | |
| 1238 | - //if value submitted was not changed, then don't validate | |
| 1239 | - $field->failed_validation = false; | |
| 1211 | +				switch ( $field_type ) { | |
| 1240 | 1212 | |
| 1241 | - unset( $field->validation_message ); | |
| 1213 | + // Captchas don't need to be re-entered. | |
| 1214 | + case 'captcha': | |
| 1242 | 1215 | |
| 1243 | -                        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); | |
| 1216 | + // Post Image fields aren't editable, so we un-fail them. | |
| 1217 | + case 'post_image': | |
| 1218 | + $field->failed_validation = false; | |
| 1219 | + unset( $field->validation_message ); | |
| 1220 | + break; | |
| 1244 | 1221 | |
| 1245 | - continue; | |
| 1246 | - } | |
| 1247 | - } | |
| 1222 | + } | |
| 1248 | 1223 | |
| 1249 | - // if here then probably we are facing the validation 'At least one field must be filled out' | |
| 1250 | -                if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) { | |
| 1251 | - unset( $field->validation_message ); | |
| 1252 | - $field->validation_message = false; | |
| 1253 | - continue; | |
| 1254 | - } | |
| 1224 | + // You can't continue inside a switch, so we do it after. | |
| 1225 | +				if( empty( $field->failed_validation ) ) { | |
| 1226 | + continue; | |
| 1227 | + } | |
| 1255 | 1228 | |
| 1256 | - $gv_valid = false; | |
| 1229 | + // checks if the No Duplicates option is not validating entry against itself, since | |
| 1230 | + // we're editing a stored entry, it would also assume it's a duplicate. | |
| 1231 | +				if( !empty( $field->noDuplicates ) ) { | |
| 1257 | 1232 | |
| 1258 | - } | |
| 1233 | + $entry = $this->get_entry(); | |
| 1259 | 1234 | |
| 1260 | - } | |
| 1235 | + // If the value of the entry is the same as the stored value | |
| 1236 | + // Then we can assume it's not a duplicate, it's the same. | |
| 1237 | +					if( !empty( $entry ) && $value == $entry[ $field->id ] ) { | |
| 1238 | + //if value submitted was not changed, then don't validate | |
| 1239 | + $field->failed_validation = false; | |
| 1261 | 1240 | |
| 1262 | - $validation_results['is_valid'] = $gv_valid; | |
| 1241 | + unset( $field->validation_message ); | |
| 1263 | 1242 | |
| 1264 | -        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); | |
| 1243 | +						do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); | |
| 1265 | 1244 | |
| 1266 | - // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) | |
| 1267 | - $this->form_after_validation = $validation_results['form']; | |
| 1245 | + continue; | |
| 1246 | + } | |
| 1247 | + } | |
| 1268 | 1248 | |
| 1269 | - return $validation_results; | |
| 1270 | - } | |
| 1249 | + // if here then probably we are facing the validation 'At least one field must be filled out' | |
| 1250 | +				if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) { | |
| 1251 | + unset( $field->validation_message ); | |
| 1252 | + $field->validation_message = false; | |
| 1253 | + continue; | |
| 1254 | + } | |
| 1271 | 1255 | |
| 1256 | + $gv_valid = false; | |
| 1272 | 1257 | |
| 1273 | - /** | |
| 1274 | - * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! | |
| 1275 | - * Get the current entry and set it if it's not yet set. | |
| 1276 | - * @return array Gravity Forms entry array | |
| 1277 | - */ | |
| 1278 | -    private function get_entry() { | |
| 1258 | + } | |
| 1279 | 1259 | |
| 1280 | -        if( empty( $this->entry ) ) { | |
| 1281 | - // Get the database value of the entry that's being edited | |
| 1282 | - $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); | |
| 1283 | - } | |
| 1260 | + } | |
| 1261 | + | |
| 1262 | + $validation_results['is_valid'] = $gv_valid; | |
| 1263 | + | |
| 1264 | +		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); | |
| 1284 | 1265 | |
| 1285 | - return $this->entry; | |
| 1286 | - } | |
| 1266 | + // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) | |
| 1267 | + $this->form_after_validation = $validation_results['form']; | |
| 1287 | 1268 | |
| 1269 | + return $validation_results; | |
| 1270 | + } | |
| 1288 | 1271 | |
| 1289 | 1272 | |
| 1290 | - // --- Filters | |
| 1273 | + /** | |
| 1274 | + * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! | |
| 1275 | + * Get the current entry and set it if it's not yet set. | |
| 1276 | + * @return array Gravity Forms entry array | |
| 1277 | + */ | |
| 1278 | +	private function get_entry() { | |
| 1291 | 1279 | |
| 1292 | - /** | |
| 1293 | - * Get the Edit Entry fields as configured in the View | |
| 1294 | - * | |
| 1295 | - * @since 1.8 | |
| 1296 | - * | |
| 1297 | - * @param int $view_id | |
| 1298 | - * | |
| 1299 | - * @return array Array of fields that are configured in the Edit tab in the Admin | |
| 1300 | - */ | |
| 1301 | -    private function get_configured_edit_fields( $form, $view_id ) { | |
| 1280 | +		if( empty( $this->entry ) ) { | |
| 1281 | + // Get the database value of the entry that's being edited | |
| 1282 | + $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); | |
| 1283 | + } | |
| 1284 | + | |
| 1285 | + return $this->entry; | |
| 1286 | + } | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + // --- Filters | |
| 1291 | + | |
| 1292 | + /** | |
| 1293 | + * Get the Edit Entry fields as configured in the View | |
| 1294 | + * | |
| 1295 | + * @since 1.8 | |
| 1296 | + * | |
| 1297 | + * @param int $view_id | |
| 1298 | + * | |
| 1299 | + * @return array Array of fields that are configured in the Edit tab in the Admin | |
| 1300 | + */ | |
| 1301 | +	private function get_configured_edit_fields( $form, $view_id ) { | |
| 1302 | 1302 | |
| 1303 | - // Get all fields for form | |
| 1304 | - $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); | |
| 1303 | + // Get all fields for form | |
| 1304 | + $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); | |
| 1305 | 1305 | |
| 1306 | - // If edit tab not yet configured, show all fields | |
| 1307 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; | |
| 1306 | + // If edit tab not yet configured, show all fields | |
| 1307 | + $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; | |
| 1308 | 1308 | |
| 1309 | - // Show hidden fields as text fields | |
| 1310 | - $form = $this->fix_hidden_fields( $form ); | |
| 1309 | + // Show hidden fields as text fields | |
| 1310 | + $form = $this->fix_hidden_fields( $form ); | |
| 1311 | 1311 | |
| 1312 | - // Hide fields depending on admin settings | |
| 1313 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); | |
| 1312 | + // Hide fields depending on admin settings | |
| 1313 | + $fields = $this->filter_fields( $form['fields'], $edit_fields ); | |
| 1314 | 1314 | |
| 1315 | - // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. | |
| 1316 | - $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); | |
| 1315 | + // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. | |
| 1316 | + $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); | |
| 1317 | 1317 | |
| 1318 | - return $fields; | |
| 1319 | - } | |
| 1318 | + return $fields; | |
| 1319 | + } | |
| 1320 | 1320 | |
| 1321 | 1321 | /** | 
| 1322 | 1322 | * @since 1.9.2 | 
| @@ -1340,376 +1340,376 @@ discard block | ||
| 1340 | 1340 | } | 
| 1341 | 1341 | |
| 1342 | 1342 | |
| 1343 | - /** | |
| 1344 | - * Filter area fields based on specified conditions | |
| 1345 | - * - This filter removes the fields that have calculation configured | |
| 1346 | - * | |
| 1347 | - * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps | |
| 1348 | - * @access private | |
| 1349 | - * @param GF_Field[] $fields | |
| 1350 | - * @param array $configured_fields | |
| 1351 | - * @since 1.5 | |
| 1352 | - * @return array $fields | |
| 1353 | - */ | |
| 1354 | -    private function filter_fields( $fields, $configured_fields ) { | |
| 1355 | - | |
| 1356 | -        if( empty( $fields ) || !is_array( $fields ) ) { | |
| 1357 | - return $fields; | |
| 1358 | - } | |
| 1359 | - | |
| 1360 | - $edit_fields = array(); | |
| 1361 | - | |
| 1362 | - $field_type_blacklist = array( | |
| 1363 | - 'page', | |
| 1364 | - ); | |
| 1365 | - | |
| 1366 | - /** | |
| 1367 | - * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. | |
| 1368 | - * @since 1.9.1 | |
| 1369 | - * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false | |
| 1370 | - */ | |
| 1371 | - $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); | |
| 1372 | - | |
| 1373 | -	    if( $hide_product_fields ) { | |
| 1374 | - $field_type_blacklist[] = 'option'; | |
| 1375 | - $field_type_blacklist[] = 'quantity'; | |
| 1376 | - $field_type_blacklist[] = 'product'; | |
| 1377 | - $field_type_blacklist[] = 'total'; | |
| 1378 | - $field_type_blacklist[] = 'shipping'; | |
| 1379 | - $field_type_blacklist[] = 'calculation'; | |
| 1380 | - } | |
| 1381 | - | |
| 1382 | - // First, remove blacklist or calculation fields | |
| 1383 | -        foreach ( $fields as $key => $field ) { | |
| 1384 | - | |
| 1385 | - // Remove the fields that have calculation properties | |
| 1386 | - // @since 1.16.2 | |
| 1387 | -            if( $field->has_calculation() ) { | |
| 1388 | - unset( $fields[ $key ] ); | |
| 1389 | - } | |
| 1390 | - | |
| 1391 | -            if( in_array( $field->type, $field_type_blacklist ) ) { | |
| 1392 | - unset( $fields[ $key ] ); | |
| 1393 | - } | |
| 1394 | - } | |
| 1395 | - | |
| 1396 | - // The Edit tab has not been configured, so we return all fields by default. | |
| 1397 | -        if( empty( $configured_fields ) ) { | |
| 1398 | - return $fields; | |
| 1399 | - } | |
| 1400 | - | |
| 1401 | - // The edit tab has been configured, so we loop through to configured settings | |
| 1402 | -        foreach ( $configured_fields as $configured_field ) { | |
| 1403 | - | |
| 1404 | - /** @var GF_Field $field */ | |
| 1405 | -	        foreach ( $fields as $field ) { | |
| 1406 | - | |
| 1407 | -                if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { | |
| 1408 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); | |
| 1409 | - break; | |
| 1410 | - } | |
| 1411 | - | |
| 1412 | - } | |
| 1413 | - | |
| 1414 | - } | |
| 1415 | - | |
| 1416 | - return $edit_fields; | |
| 1417 | - | |
| 1418 | - } | |
| 1419 | - | |
| 1420 | - /** | |
| 1421 | - * Override GF Form field properties with the ones defined on the View | |
| 1422 | - * @param GF_Field $field GF Form field object | |
| 1423 | - * @param array $setting GV field options | |
| 1424 | - * @since 1.5 | |
| 1425 | - * @return array | |
| 1426 | - */ | |
| 1427 | -    private function merge_field_properties( $field, $field_setting ) { | |
| 1428 | - | |
| 1429 | - $return_field = $field; | |
| 1430 | - | |
| 1431 | -        if( empty( $field_setting['show_label'] ) ) { | |
| 1432 | - $return_field->label = ''; | |
| 1433 | -        } elseif ( !empty( $field_setting['custom_label'] ) ) { | |
| 1434 | - $return_field->label = $field_setting['custom_label']; | |
| 1435 | - } | |
| 1436 | - | |
| 1437 | -        if( !empty( $field_setting['custom_class'] ) ) { | |
| 1438 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); | |
| 1439 | - } | |
| 1440 | - | |
| 1441 | - /** | |
| 1442 | - * Normalize page numbers - avoid conflicts with page validation | |
| 1443 | - * @since 1.6 | |
| 1444 | - */ | |
| 1445 | - $return_field->pageNumber = 1; | |
| 1446 | - | |
| 1447 | - return $return_field; | |
| 1448 | - | |
| 1449 | - } | |
| 1450 | - | |
| 1451 | - /** | |
| 1452 | - * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property | |
| 1453 | - * | |
| 1454 | - * @since 1.9.1 | |
| 1455 | - * | |
| 1456 | - * @param array|GF_Field[] $fields Gravity Forms form fields | |
| 1457 | - * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration | |
| 1458 | - * @param array $form GF Form array | |
| 1459 | - * @param int $view_id View ID | |
| 1460 | - * | |
| 1461 | - * @return array Possibly modified form array | |
| 1462 | - */ | |
| 1463 | -    function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { | |
| 1464 | - | |
| 1465 | - /** | |
| 1466 | - * @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 | |
| 1467 | - * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. | |
| 1468 | - * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions | |
| 1469 | - * @since 1.9.1 | |
| 1470 | - * @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. | |
| 1471 | - * @param array $form GF Form array | |
| 1472 | - * @param int $view_id View ID | |
| 1473 | - */ | |
| 1474 | - $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); | |
| 1475 | - | |
| 1476 | -	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { | |
| 1477 | -            foreach( $fields as $k => $field ) { | |
| 1478 | -                if( $field->adminOnly ) { | |
| 1479 | - unset( $fields[ $k ] ); | |
| 1480 | - } | |
| 1481 | - } | |
| 1482 | - return $fields; | |
| 1483 | - } | |
| 1484 | - | |
| 1485 | -	    foreach( $fields as &$field ) { | |
| 1486 | - $field->adminOnly = false; | |
| 1487 | - } | |
| 1488 | - | |
| 1489 | - return $fields; | |
| 1490 | - } | |
| 1491 | - | |
| 1492 | - // --- Conditional Logic | |
| 1493 | - | |
| 1494 | - /** | |
| 1495 | - * Remove the conditional logic rules from the form button and the form fields, if needed. | |
| 1496 | - * | |
| 1497 | - * @since 1.9 | |
| 1498 | - * | |
| 1499 | - * @param array $form Gravity Forms form | |
| 1500 | - * @return array Modified form, if not using Conditional Logic | |
| 1501 | - */ | |
| 1502 | -    function filter_conditional_logic( $form ) { | |
| 1503 | - | |
| 1504 | - /** | |
| 1505 | - * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? | |
| 1506 | - * @since 1.9 | |
| 1507 | - * @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 | |
| 1508 | - * @param array $form Gravity Forms form | |
| 1509 | - */ | |
| 1510 | - $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); | |
| 1511 | - | |
| 1512 | -        if( $use_conditional_logic ) { | |
| 1513 | - return $form; | |
| 1514 | - } | |
| 1515 | - | |
| 1516 | -        foreach( $form['fields'] as &$field ) { | |
| 1517 | - /* @var GF_Field $field */ | |
| 1518 | - $field->conditionalLogic = null; | |
| 1519 | - } | |
| 1520 | - | |
| 1521 | - unset( $form['button']['conditionalLogic'] ); | |
| 1522 | - | |
| 1523 | - return $form; | |
| 1524 | - | |
| 1525 | - } | |
| 1526 | - | |
| 1527 | - /** | |
| 1528 | - * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen | |
| 1529 | - * | |
| 1530 | - * @since 1.9 | |
| 1531 | - * | |
| 1532 | - * @param $has_conditional_logic | |
| 1533 | - * @param $form | |
| 1534 | - * @return mixed|void | |
| 1535 | - */ | |
| 1536 | -    function manage_conditional_logic( $has_conditional_logic, $form ) { | |
| 1537 | - | |
| 1538 | -        if( ! $this->is_edit_entry() ) { | |
| 1539 | - return $has_conditional_logic; | |
| 1540 | - } | |
| 1541 | - | |
| 1542 | - return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); | |
| 1543 | - } | |
| 1544 | - | |
| 1545 | - | |
| 1546 | - // --- User checks and nonces | |
| 1547 | - | |
| 1548 | - /** | |
| 1549 | - * Check if the user can edit the entry | |
| 1550 | - * | |
| 1551 | - * - Is the nonce valid? | |
| 1552 | - * - Does the user have the right caps for the entry | |
| 1553 | - * - Is the entry in the trash? | |
| 1554 | - * | |
| 1555 | - * @todo Move to GVCommon | |
| 1556 | - * | |
| 1557 | - * @param boolean $echo Show error messages in the form? | |
| 1558 | - * @return boolean True: can edit form. False: nope. | |
| 1559 | - */ | |
| 1560 | -    function user_can_edit_entry( $echo = false ) { | |
| 1561 | - | |
| 1562 | - $error = NULL; | |
| 1563 | - | |
| 1564 | - /** | |
| 1565 | - * 1. Permalinks are turned off | |
| 1566 | - * 2. There are two entries embedded using oEmbed | |
| 1567 | - * 3. One of the entries has just been saved | |
| 1568 | - */ | |
| 1569 | -        if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { | |
| 1570 | - | |
| 1571 | - $error = true; | |
| 1572 | - | |
| 1573 | - } | |
| 1574 | - | |
| 1575 | -        if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { | |
| 1576 | - | |
| 1577 | - $error = true; | |
| 1578 | - | |
| 1579 | -        } elseif( ! $this->verify_nonce() ) { | |
| 1580 | - | |
| 1581 | - /** | |
| 1582 | - * If the Entry is embedded, there may be two entries on the same page. | |
| 1583 | - * If that's the case, and one is being edited, the other should fail gracefully and not display an error. | |
| 1584 | - */ | |
| 1585 | -            if( GravityView_oEmbed::getInstance()->get_entry_id() ) { | |
| 1586 | - $error = true; | |
| 1587 | -            } else { | |
| 1588 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); | |
| 1589 | - } | |
| 1343 | + /** | |
| 1344 | + * Filter area fields based on specified conditions | |
| 1345 | + * - This filter removes the fields that have calculation configured | |
| 1346 | + * | |
| 1347 | + * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps | |
| 1348 | + * @access private | |
| 1349 | + * @param GF_Field[] $fields | |
| 1350 | + * @param array $configured_fields | |
| 1351 | + * @since 1.5 | |
| 1352 | + * @return array $fields | |
| 1353 | + */ | |
| 1354 | +	private function filter_fields( $fields, $configured_fields ) { | |
| 1590 | 1355 | |
| 1591 | - } | |
| 1592 | - | |
| 1593 | -        if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { | |
| 1594 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); | |
| 1595 | - } | |
| 1596 | - | |
| 1597 | -        if( $this->entry['status'] === 'trash' ) { | |
| 1598 | -            $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); | |
| 1599 | - } | |
| 1356 | +		if( empty( $fields ) || !is_array( $fields ) ) { | |
| 1357 | + return $fields; | |
| 1358 | + } | |
| 1600 | 1359 | |
| 1601 | - // No errors; everything's fine here! | |
| 1602 | -        if( empty( $error ) ) { | |
| 1603 | - return true; | |
| 1604 | - } | |
| 1360 | + $edit_fields = array(); | |
| 1361 | + | |
| 1362 | + $field_type_blacklist = array( | |
| 1363 | + 'page', | |
| 1364 | + ); | |
| 1365 | + | |
| 1366 | + /** | |
| 1367 | + * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. | |
| 1368 | + * @since 1.9.1 | |
| 1369 | + * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false | |
| 1370 | + */ | |
| 1371 | + $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); | |
| 1372 | + | |
| 1373 | +		if( $hide_product_fields ) { | |
| 1374 | + $field_type_blacklist[] = 'option'; | |
| 1375 | + $field_type_blacklist[] = 'quantity'; | |
| 1376 | + $field_type_blacklist[] = 'product'; | |
| 1377 | + $field_type_blacklist[] = 'total'; | |
| 1378 | + $field_type_blacklist[] = 'shipping'; | |
| 1379 | + $field_type_blacklist[] = 'calculation'; | |
| 1380 | + } | |
| 1605 | 1381 | |
| 1606 | -        if( $echo && $error !== true ) { | |
| 1382 | + // First, remove blacklist or calculation fields | |
| 1383 | +		foreach ( $fields as $key => $field ) { | |
| 1607 | 1384 | |
| 1608 | - $error = esc_html( $error ); | |
| 1385 | + // Remove the fields that have calculation properties | |
| 1386 | + // @since 1.16.2 | |
| 1387 | +			if( $field->has_calculation() ) { | |
| 1388 | + unset( $fields[ $key ] ); | |
| 1389 | + } | |
| 1609 | 1390 | |
| 1610 | - /** | |
| 1611 | - * @since 1.9 | |
| 1612 | - */ | |
| 1613 | -	        if ( ! empty( $this->entry ) ) { | |
| 1614 | -		        $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;" ) ); | |
| 1615 | - } | |
| 1391 | +			if( in_array( $field->type, $field_type_blacklist ) ) { | |
| 1392 | + unset( $fields[ $key ] ); | |
| 1393 | + } | |
| 1394 | + } | |
| 1616 | 1395 | |
| 1617 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); | |
| 1618 | - } | |
| 1396 | + // The Edit tab has not been configured, so we return all fields by default. | |
| 1397 | +		if( empty( $configured_fields ) ) { | |
| 1398 | + return $fields; | |
| 1399 | + } | |
| 1619 | 1400 | |
| 1620 | -        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); | |
| 1401 | + // The edit tab has been configured, so we loop through to configured settings | |
| 1402 | +		foreach ( $configured_fields as $configured_field ) { | |
| 1621 | 1403 | |
| 1622 | - return false; | |
| 1623 | - } | |
| 1404 | + /** @var GF_Field $field */ | |
| 1405 | +			foreach ( $fields as $field ) { | |
| 1624 | 1406 | |
| 1407 | +				if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { | |
| 1408 | + $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); | |
| 1409 | + break; | |
| 1410 | + } | |
| 1625 | 1411 | |
| 1626 | - /** | |
| 1627 | - * Check whether a field is editable by the current user, and optionally display an error message | |
| 1628 | - * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities | |
| 1629 | - * @param array $field Field or field settings array | |
| 1630 | - * @param boolean $echo Whether to show error message telling user they aren't allowed | |
| 1631 | - * @return boolean True: user can edit the current field; False: nope, they can't. | |
| 1632 | - */ | |
| 1633 | -    private function user_can_edit_field( $field, $echo = false ) { | |
| 1634 | - | |
| 1635 | - $error = NULL; | |
| 1412 | + } | |
| 1636 | 1413 | |
| 1637 | -        if( ! $this->check_user_cap_edit_field( $field ) ) { | |
| 1638 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); | |
| 1639 | - } | |
| 1414 | + } | |
| 1640 | 1415 | |
| 1641 | - // No errors; everything's fine here! | |
| 1642 | -        if( empty( $error ) ) { | |
| 1643 | - return true; | |
| 1644 | - } | |
| 1416 | + return $edit_fields; | |
| 1645 | 1417 | |
| 1646 | -        if( $echo ) { | |
| 1647 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); | |
| 1648 | - } | |
| 1649 | - | |
| 1650 | -        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); | |
| 1418 | + } | |
| 1651 | 1419 | |
| 1652 | - return false; | |
| 1420 | + /** | |
| 1421 | + * Override GF Form field properties with the ones defined on the View | |
| 1422 | + * @param GF_Field $field GF Form field object | |
| 1423 | + * @param array $setting GV field options | |
| 1424 | + * @since 1.5 | |
| 1425 | + * @return array | |
| 1426 | + */ | |
| 1427 | +	private function merge_field_properties( $field, $field_setting ) { | |
| 1653 | 1428 | |
| 1654 | - } | |
| 1429 | + $return_field = $field; | |
| 1655 | 1430 | |
| 1431 | +		if( empty( $field_setting['show_label'] ) ) { | |
| 1432 | + $return_field->label = ''; | |
| 1433 | +		} elseif ( !empty( $field_setting['custom_label'] ) ) { | |
| 1434 | + $return_field->label = $field_setting['custom_label']; | |
| 1435 | + } | |
| 1656 | 1436 | |
| 1657 | - /** | |
| 1658 | - * checks if user has permissions to edit a specific field | |
| 1659 | - * | |
| 1660 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! | |
| 1661 | - * | |
| 1662 | - * @param [type] $field [description] | |
| 1663 | - * @return bool | |
| 1664 | - */ | |
| 1665 | -    private function check_user_cap_edit_field( $field ) { | |
| 1437 | +		if( !empty( $field_setting['custom_class'] ) ) { | |
| 1438 | + $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); | |
| 1439 | + } | |
| 1666 | 1440 | |
| 1667 | - // If they can edit any entries (as defined in Gravity Forms), we're good. | |
| 1668 | -        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { | |
| 1669 | - return true; | |
| 1670 | - } | |
| 1441 | + /** | |
| 1442 | + * Normalize page numbers - avoid conflicts with page validation | |
| 1443 | + * @since 1.6 | |
| 1444 | + */ | |
| 1445 | + $return_field->pageNumber = 1; | |
| 1671 | 1446 | |
| 1672 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; | |
| 1447 | + return $return_field; | |
| 1673 | 1448 | |
| 1674 | - // If the field has custom editing capaibilities set, check those | |
| 1675 | -        if( $field_cap ) { | |
| 1676 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); | |
| 1677 | - } | |
| 1678 | - | |
| 1679 | - return false; | |
| 1680 | - } | |
| 1449 | + } | |
| 1681 | 1450 | |
| 1451 | + /** | |
| 1452 | + * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property | |
| 1453 | + * | |
| 1454 | + * @since 1.9.1 | |
| 1455 | + * | |
| 1456 | + * @param array|GF_Field[] $fields Gravity Forms form fields | |
| 1457 | + * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration | |
| 1458 | + * @param array $form GF Form array | |
| 1459 | + * @param int $view_id View ID | |
| 1460 | + * | |
| 1461 | + * @return array Possibly modified form array | |
| 1462 | + */ | |
| 1463 | +	function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { | |
| 1464 | + | |
| 1465 | + /** | |
| 1466 | + * @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 | |
| 1467 | + * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. | |
| 1468 | + * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions | |
| 1469 | + * @since 1.9.1 | |
| 1470 | + * @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. | |
| 1471 | + * @param array $form GF Form array | |
| 1472 | + * @param int $view_id View ID | |
| 1473 | + */ | |
| 1474 | + $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); | |
| 1475 | + | |
| 1476 | +		if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { | |
| 1477 | +			foreach( $fields as $k => $field ) { | |
| 1478 | +				if( $field->adminOnly ) { | |
| 1479 | + unset( $fields[ $k ] ); | |
| 1480 | + } | |
| 1481 | + } | |
| 1482 | + return $fields; | |
| 1483 | + } | |
| 1682 | 1484 | |
| 1683 | - /** | |
| 1684 | - * Is the current nonce valid for editing the entry? | |
| 1685 | - * @return boolean | |
| 1686 | - */ | |
| 1687 | -    public function verify_nonce() { | |
| 1485 | +		foreach( $fields as &$field ) { | |
| 1486 | + $field->adminOnly = false; | |
| 1487 | + } | |
| 1488 | + | |
| 1489 | + return $fields; | |
| 1490 | + } | |
| 1491 | + | |
| 1492 | + // --- Conditional Logic | |
| 1493 | + | |
| 1494 | + /** | |
| 1495 | + * Remove the conditional logic rules from the form button and the form fields, if needed. | |
| 1496 | + * | |
| 1497 | + * @since 1.9 | |
| 1498 | + * | |
| 1499 | + * @param array $form Gravity Forms form | |
| 1500 | + * @return array Modified form, if not using Conditional Logic | |
| 1501 | + */ | |
| 1502 | +	function filter_conditional_logic( $form ) { | |
| 1503 | + | |
| 1504 | + /** | |
| 1505 | + * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? | |
| 1506 | + * @since 1.9 | |
| 1507 | + * @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 | |
| 1508 | + * @param array $form Gravity Forms form | |
| 1509 | + */ | |
| 1510 | + $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); | |
| 1511 | + | |
| 1512 | +		if( $use_conditional_logic ) { | |
| 1513 | + return $form; | |
| 1514 | + } | |
| 1515 | + | |
| 1516 | +		foreach( $form['fields'] as &$field ) { | |
| 1517 | + /* @var GF_Field $field */ | |
| 1518 | + $field->conditionalLogic = null; | |
| 1519 | + } | |
| 1520 | + | |
| 1521 | + unset( $form['button']['conditionalLogic'] ); | |
| 1522 | + | |
| 1523 | + return $form; | |
| 1524 | + | |
| 1525 | + } | |
| 1526 | + | |
| 1527 | + /** | |
| 1528 | + * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen | |
| 1529 | + * | |
| 1530 | + * @since 1.9 | |
| 1531 | + * | |
| 1532 | + * @param $has_conditional_logic | |
| 1533 | + * @param $form | |
| 1534 | + * @return mixed|void | |
| 1535 | + */ | |
| 1536 | +	function manage_conditional_logic( $has_conditional_logic, $form ) { | |
| 1537 | + | |
| 1538 | +		if( ! $this->is_edit_entry() ) { | |
| 1539 | + return $has_conditional_logic; | |
| 1540 | + } | |
| 1541 | + | |
| 1542 | + return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); | |
| 1543 | + } | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + // --- User checks and nonces | |
| 1547 | + | |
| 1548 | + /** | |
| 1549 | + * Check if the user can edit the entry | |
| 1550 | + * | |
| 1551 | + * - Is the nonce valid? | |
| 1552 | + * - Does the user have the right caps for the entry | |
| 1553 | + * - Is the entry in the trash? | |
| 1554 | + * | |
| 1555 | + * @todo Move to GVCommon | |
| 1556 | + * | |
| 1557 | + * @param boolean $echo Show error messages in the form? | |
| 1558 | + * @return boolean True: can edit form. False: nope. | |
| 1559 | + */ | |
| 1560 | +	function user_can_edit_entry( $echo = false ) { | |
| 1561 | + | |
| 1562 | + $error = NULL; | |
| 1563 | + | |
| 1564 | + /** | |
| 1565 | + * 1. Permalinks are turned off | |
| 1566 | + * 2. There are two entries embedded using oEmbed | |
| 1567 | + * 3. One of the entries has just been saved | |
| 1568 | + */ | |
| 1569 | +		if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { | |
| 1570 | + | |
| 1571 | + $error = true; | |
| 1572 | + | |
| 1573 | + } | |
| 1574 | + | |
| 1575 | +		if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { | |
| 1576 | + | |
| 1577 | + $error = true; | |
| 1578 | + | |
| 1579 | +		} elseif( ! $this->verify_nonce() ) { | |
| 1580 | + | |
| 1581 | + /** | |
| 1582 | + * If the Entry is embedded, there may be two entries on the same page. | |
| 1583 | + * If that's the case, and one is being edited, the other should fail gracefully and not display an error. | |
| 1584 | + */ | |
| 1585 | +			if( GravityView_oEmbed::getInstance()->get_entry_id() ) { | |
| 1586 | + $error = true; | |
| 1587 | +			} else { | |
| 1588 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); | |
| 1589 | + } | |
| 1590 | + | |
| 1591 | + } | |
| 1592 | + | |
| 1593 | +		if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { | |
| 1594 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview'); | |
| 1595 | + } | |
| 1688 | 1596 | |
| 1689 | - // Verify form submitted for editing single | |
| 1690 | -        if( $this->is_edit_entry_submission() ) { | |
| 1691 | - $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); | |
| 1692 | - } | |
| 1597 | +		if( $this->entry['status'] === 'trash' ) { | |
| 1598 | +			$error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); | |
| 1599 | + } | |
| 1600 | + | |
| 1601 | + // No errors; everything's fine here! | |
| 1602 | +		if( empty( $error ) ) { | |
| 1603 | + return true; | |
| 1604 | + } | |
| 1605 | + | |
| 1606 | +		if( $echo && $error !== true ) { | |
| 1607 | + | |
| 1608 | + $error = esc_html( $error ); | |
| 1609 | + | |
| 1610 | + /** | |
| 1611 | + * @since 1.9 | |
| 1612 | + */ | |
| 1613 | +			if ( ! empty( $this->entry ) ) { | |
| 1614 | +				$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;" ) ); | |
| 1615 | + } | |
| 1616 | + | |
| 1617 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); | |
| 1618 | + } | |
| 1619 | + | |
| 1620 | +		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); | |
| 1621 | + | |
| 1622 | + return false; | |
| 1623 | + } | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + /** | |
| 1627 | + * Check whether a field is editable by the current user, and optionally display an error message | |
| 1628 | + * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities | |
| 1629 | + * @param array $field Field or field settings array | |
| 1630 | + * @param boolean $echo Whether to show error message telling user they aren't allowed | |
| 1631 | + * @return boolean True: user can edit the current field; False: nope, they can't. | |
| 1632 | + */ | |
| 1633 | +	private function user_can_edit_field( $field, $echo = false ) { | |
| 1634 | + | |
| 1635 | + $error = NULL; | |
| 1636 | + | |
| 1637 | +		if( ! $this->check_user_cap_edit_field( $field ) ) { | |
| 1638 | + $error = __( 'You do not have permission to edit this field.', 'gravityview'); | |
| 1639 | + } | |
| 1640 | + | |
| 1641 | + // No errors; everything's fine here! | |
| 1642 | +		if( empty( $error ) ) { | |
| 1643 | + return true; | |
| 1644 | + } | |
| 1645 | + | |
| 1646 | +		if( $echo ) { | |
| 1647 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); | |
| 1648 | + } | |
| 1649 | + | |
| 1650 | +		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); | |
| 1651 | + | |
| 1652 | + return false; | |
| 1693 | 1653 | |
| 1694 | - // Verify | |
| 1695 | -        else if( ! $this->is_edit_entry() ) { | |
| 1696 | - $valid = false; | |
| 1697 | - } | |
| 1654 | + } | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + /** | |
| 1658 | + * checks if user has permissions to edit a specific field | |
| 1659 | + * | |
| 1660 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! | |
| 1661 | + * | |
| 1662 | + * @param [type] $field [description] | |
| 1663 | + * @return bool | |
| 1664 | + */ | |
| 1665 | +	private function check_user_cap_edit_field( $field ) { | |
| 1698 | 1666 | |
| 1699 | -        else { | |
| 1700 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); | |
| 1701 | - } | |
| 1667 | + // If they can edit any entries (as defined in Gravity Forms), we're good. | |
| 1668 | +		if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { | |
| 1669 | + return true; | |
| 1670 | + } | |
| 1671 | + | |
| 1672 | + $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; | |
| 1673 | + | |
| 1674 | + // If the field has custom editing capaibilities set, check those | |
| 1675 | +		if( $field_cap ) { | |
| 1676 | + return GVCommon::has_cap( $field['allow_edit_cap'] ); | |
| 1677 | + } | |
| 1678 | + | |
| 1679 | + return false; | |
| 1680 | + } | |
| 1702 | 1681 | |
| 1703 | - /** | |
| 1704 | - * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. | |
| 1705 | - * @since 1.13 | |
| 1706 | - * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated | |
| 1707 | - * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry | |
| 1708 | - */ | |
| 1709 | - $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); | |
| 1710 | 1682 | |
| 1711 | - return $valid; | |
| 1712 | - } | |
| 1683 | + /** | |
| 1684 | + * Is the current nonce valid for editing the entry? | |
| 1685 | + * @return boolean | |
| 1686 | + */ | |
| 1687 | +	public function verify_nonce() { | |
| 1688 | + | |
| 1689 | + // Verify form submitted for editing single | |
| 1690 | +		if( $this->is_edit_entry_submission() ) { | |
| 1691 | + $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); | |
| 1692 | + } | |
| 1693 | + | |
| 1694 | + // Verify | |
| 1695 | +		else if( ! $this->is_edit_entry() ) { | |
| 1696 | + $valid = false; | |
| 1697 | + } | |
| 1698 | + | |
| 1699 | +		else { | |
| 1700 | + $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); | |
| 1701 | + } | |
| 1702 | + | |
| 1703 | + /** | |
| 1704 | + * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. | |
| 1705 | + * @since 1.13 | |
| 1706 | + * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated | |
| 1707 | + * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry | |
| 1708 | + */ | |
| 1709 | + $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); | |
| 1710 | + | |
| 1711 | + return $valid; | |
| 1712 | + } | |
| 1713 | 1713 | |
| 1714 | 1714 | |
| 1715 | 1715 | |
| @@ -71,7 +71,7 @@ discard block | ||
| 71 | 71 | */ | 
| 72 | 72 |  	public function __construct( $prevent_multiple_instances = '' ) { | 
| 73 | 73 | |
| 74 | -		if( $prevent_multiple_instances === 'get_instance' ) { | |
| 74 | +		if ( $prevent_multiple_instances === 'get_instance' ) { | |
| 75 | 75 | return parent::__construct(); | 
| 76 | 76 | } | 
| 77 | 77 | |
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | */ | 
| 84 | 84 |  	public static function get_instance() { | 
| 85 | 85 | |
| 86 | -		if( empty( self::$instance ) ) { | |
| 86 | +		if ( empty( self::$instance ) ) { | |
| 87 | 87 | self::$instance = new self( 'get_instance' ); | 
| 88 | 88 | } | 
| 89 | 89 | |
| @@ -106,11 +106,11 @@ discard block | ||
| 106 | 106 | * Prevent Gravity Forms from showing the uninstall tab on the settings page | 
| 107 | 107 | * @hack | 
| 108 | 108 | */ | 
| 109 | -		if( $caps === $this->_capabilities_uninstall ) { | |
| 109 | +		if ( $caps === $this->_capabilities_uninstall ) { | |
| 110 | 110 | return false; | 
| 111 | 111 | } | 
| 112 | 112 | |
| 113 | -		if( empty( $caps ) ) { | |
| 113 | +		if ( empty( $caps ) ) { | |
| 114 | 114 | $caps = array( 'gravityview_full_access' ); | 
| 115 | 115 | } | 
| 116 | 116 | |
| @@ -133,7 +133,7 @@ discard block | ||
| 133 | 133 | add_filter( 'gform_addon_app_settings_menu_gravityview', array( $this, 'modify_app_settings_menu_title' ) ); | 
| 134 | 134 | |
| 135 | 135 | /** @since 1.7.6 */ | 
| 136 | -		add_action('network_admin_menu', array( $this, 'add_network_menu' ) ); | |
| 136 | + add_action( 'network_admin_menu', array( $this, 'add_network_menu' ) ); | |
| 137 | 137 | |
| 138 | 138 | parent::init_admin(); | 
| 139 | 139 | } | 
| @@ -147,7 +147,7 @@ discard block | ||
| 147 | 147 | */ | 
| 148 | 148 |  	public function modify_app_settings_menu_title( $setting_tabs ) { | 
| 149 | 149 | |
| 150 | - $setting_tabs[0]['label'] = __( 'GravityView Settings', 'gravityview'); | |
| 150 | + $setting_tabs[ 0 ][ 'label' ] = __( 'GravityView Settings', 'gravityview' ); | |
| 151 | 151 | |
| 152 | 152 | return $setting_tabs; | 
| 153 | 153 | } | 
| @@ -164,11 +164,11 @@ discard block | ||
| 164 | 164 | */ | 
| 165 | 165 |  	private function _load_license_handler() { | 
| 166 | 166 | |
| 167 | -		if( !empty( $this->License_Handler ) ) { | |
| 167 | +		if ( ! empty( $this->License_Handler ) ) { | |
| 168 | 168 | return; | 
| 169 | 169 | } | 
| 170 | 170 | |
| 171 | - require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php'); | |
| 171 | + require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php' ); | |
| 172 | 172 | |
| 173 | 173 | $this->License_Handler = GV_License_Handler::get_instance( $this ); | 
| 174 | 174 | } | 
| @@ -180,60 +180,60 @@ discard block | ||
| 180 | 180 |  	function license_key_notice() { | 
| 181 | 181 | |
| 182 | 182 | // Only show on GravityView pages | 
| 183 | -		if( ! gravityview_is_admin_page() ) { | |
| 183 | +		if ( ! gravityview_is_admin_page() ) { | |
| 184 | 184 | return; | 
| 185 | 185 | } | 
| 186 | 186 | |
| 187 | -		$license_status = self::getSetting('license_key_status'); | |
| 188 | -		$license_id = self::getSetting('license_key'); | |
| 187 | + $license_status = self::getSetting( 'license_key_status' ); | |
| 188 | + $license_id = self::getSetting( 'license_key' ); | |
| 189 | 189 | $license_id = empty( $license_id ) ? 'license' : $license_id; | 
| 190 | 190 | |
| 191 | -		$message = esc_html__('Your GravityView license %s. This means you’re missing out on updates and support! %sActivate your license%s or %sget a license here%s.', 'gravityview'); | |
| 191 | + $message = esc_html__( 'Your GravityView license %s. This means you’re missing out on updates and support! %sActivate your license%s or %sget a license here%s.', 'gravityview' ); | |
| 192 | 192 | |
| 193 | 193 | /** | 
| 194 | 194 | * I wanted to remove the period from after the buttons in the string, | 
| 195 | 195 | * but didn't want to mess up the translation strings for the translators. | 
| 196 | 196 | */ | 
| 197 | 197 | $message = mb_substr( $message, 0, mb_strlen( $message ) - 1 ); | 
| 198 | -		$title = __('Inactive License', 'gravityview'); | |
| 198 | + $title = __( 'Inactive License', 'gravityview' ); | |
| 199 | 199 | $status = ''; | 
| 200 | 200 | $update_below = false; | 
| 201 | 201 | $primary_button_link = admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ); | 
| 202 | 202 |  		switch ( $license_status ) { | 
| 203 | 203 | case 'invalid': | 
| 204 | -				$title = __('Invalid License', 'gravityview'); | |
| 205 | -				$status = __('is invalid', 'gravityview'); | |
| 204 | + $title = __( 'Invalid License', 'gravityview' ); | |
| 205 | + $status = __( 'is invalid', 'gravityview' ); | |
| 206 | 206 | break; | 
| 207 | 207 | case 'deactivated': | 
| 208 | -				$status = __('is inactive', 'gravityview'); | |
| 209 | -				$update_below = __('Activate your license key below.', 'gravityview'); | |
| 208 | + $status = __( 'is inactive', 'gravityview' ); | |
| 209 | + $update_below = __( 'Activate your license key below.', 'gravityview' ); | |
| 210 | 210 | break; | 
| 211 | 211 | /** @noinspection PhpMissingBreakStatementInspection */ | 
| 212 | 212 | case '': | 
| 213 | 213 | $license_status = 'site_inactive'; | 
| 214 | 214 | // break intentionally left blank | 
| 215 | 215 | case 'site_inactive': | 
| 216 | -				$status = __('has not been activated', 'gravityview'); | |
| 217 | -				$update_below = __('Activate your license key below.', 'gravityview'); | |
| 216 | + $status = __( 'has not been activated', 'gravityview' ); | |
| 217 | + $update_below = __( 'Activate your license key below.', 'gravityview' ); | |
| 218 | 218 | break; | 
| 219 | 219 | } | 
| 220 | - $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice'; | |
| 220 | + $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content=' . $license_status . '&utm_campaign=Admin%20Notice'; | |
| 221 | 221 | |
| 222 | 222 | // Show a different notice on settings page for inactive licenses (hide the buttons) | 
| 223 | -		if( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { | |
| 223 | +		if ( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { | |
| 224 | 224 | $message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' ); | 
| 225 | 225 |  		} else { | 
| 226 | 226 | $message = sprintf( $message, $status, "\n\n" . '<a href="' . $primary_button_link . '" class="button button-primary">', '</a>', '<a href="' . esc_url( $url ) . '" class="button button-secondary">', '</a>' ); | 
| 227 | 227 | } | 
| 228 | 228 | |
| 229 | -		if( !empty( $status ) ) { | |
| 229 | +		if ( ! empty( $status ) ) { | |
| 230 | 230 | GravityView_Admin_Notices::add_notice( array( | 
| 231 | 231 | 'message' => $message, | 
| 232 | 232 | 'class' => 'updated', | 
| 233 | 233 | 'title' => $title, | 
| 234 | 234 | 'cap' => 'gravityview_edit_settings', | 
| 235 | - 'dismiss' => sha1( $license_status.'_'.$license_id ), | |
| 236 | - )); | |
| 235 | + 'dismiss' => sha1( $license_status . '_' . $license_id ), | |
| 236 | + ) ); | |
| 237 | 237 | } | 
| 238 | 238 | } | 
| 239 | 239 | |
| @@ -245,7 +245,7 @@ discard block | ||
| 245 | 245 | |
| 246 | 246 | $styles = parent::styles(); | 
| 247 | 247 | |
| 248 | - $styles[] = array( | |
| 248 | + $styles[ ] = array( | |
| 249 | 249 | 'handle' => 'gravityview_settings', | 
| 250 | 250 | 'src' => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ), | 
| 251 | 251 | 'version' => GravityView_Plugin::version, | 
| @@ -268,7 +268,7 @@ discard block | ||
| 268 | 268 | * @return void | 
| 269 | 269 | */ | 
| 270 | 270 |  	public function add_network_menu() { | 
| 271 | -		if( GravityView_Plugin::is_network_activated() ) { | |
| 271 | +		if ( GravityView_Plugin::is_network_activated() ) { | |
| 272 | 272 |  			add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' ); | 
| 273 | 273 | } | 
| 274 | 274 | } | 
| @@ -285,7 +285,7 @@ discard block | ||
| 285 | 285 | * If multisite and not network admin, we don't want the settings to show. | 
| 286 | 286 | * @since 1.7.6 | 
| 287 | 287 | */ | 
| 288 | - $show_submenu = !is_multisite() || is_main_site() || !GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); | |
| 288 | + $show_submenu = ! is_multisite() || is_main_site() || ! GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); | |
| 289 | 289 | |
| 290 | 290 | /** | 
| 291 | 291 | * Override whether to show the Settings menu on a per-blog basis. | 
| @@ -294,7 +294,7 @@ discard block | ||
| 294 | 294 | */ | 
| 295 | 295 | $show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu ); | 
| 296 | 296 | |
| 297 | -		if( $show_submenu ) { | |
| 297 | +		if ( $show_submenu ) { | |
| 298 | 298 | add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) ); | 
| 299 | 299 | } | 
| 300 | 300 | } | 
| @@ -325,7 +325,7 @@ discard block | ||
| 325 | 325 | /** | 
| 326 | 326 | * Backward compatibility with Redux | 
| 327 | 327 | */ | 
| 328 | -		if( $setting_name === 'license' ) { | |
| 328 | +		if ( $setting_name === 'license' ) { | |
| 329 | 329 | return array( | 
| 330 | 330 | 'license' => parent::get_app_setting( 'license_key' ), | 
| 331 | 331 | 'status' => parent::get_app_setting( 'license_key_status' ), | 
| @@ -389,7 +389,7 @@ discard block | ||
| 389 | 389 | |
| 390 | 390 | $return = $text . $activation; | 
| 391 | 391 | |
| 392 | -		if( $echo ) { | |
| 392 | +		if ( $echo ) { | |
| 393 | 393 | echo $return; | 
| 394 | 394 | } | 
| 395 | 395 | |
| @@ -416,15 +416,15 @@ discard block | ||
| 416 | 416 | */ | 
| 417 | 417 |  	public function settings_submit( $field, $echo = true ) { | 
| 418 | 418 | |
| 419 | -		$field['type']  = ( isset($field['type']) && in_array( $field['type'], array('submit','reset','button') ) ) ? $field['type'] : 'submit'; | |
| 419 | + $field[ 'type' ] = ( isset( $field[ 'type' ] ) && in_array( $field[ 'type' ], array( 'submit', 'reset', 'button' ) ) ) ? $field[ 'type' ] : 'submit'; | |
| 420 | 420 | |
| 421 | 421 | $attributes = $this->get_field_attributes( $field ); | 
| 422 | 422 | $default_value = rgar( $field, 'value' ) ? rgar( $field, 'value' ) : rgar( $field, 'default_value' ); | 
| 423 | - $value = $this->get_setting( $field['name'], $default_value ); | |
| 423 | + $value = $this->get_setting( $field[ 'name' ], $default_value ); | |
| 424 | 424 | |
| 425 | 425 | |
| 426 | - $attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton'; | |
| 427 | - $name = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_'.$field['name']; | |
| 426 | + $attributes[ 'class' ] = isset( $attributes[ 'class' ] ) ? esc_attr( $attributes[ 'class' ] ) : 'button-primary gfbutton'; | |
| 427 | + $name = ( $field[ 'name' ] === 'gform-settings-save' ) ? $field[ 'name' ] : '_gaddon_setting_' . $field[ 'name' ]; | |
| 428 | 428 | |
| 429 | 429 |  		if ( empty( $value ) ) { | 
| 430 | 430 | $value = __( 'Update Settings', 'gravityview' ); | 
| @@ -433,7 +433,7 @@ discard block | ||
| 433 | 433 | $attributes = $this->get_field_attributes( $field ); | 
| 434 | 434 | |
| 435 | 435 | $html = '<input | 
| 436 | - type="' . $field['type'] . '" | |
| 436 | + type="' . $field[ 'type' ] . '" | |
| 437 | 437 | name="' . esc_attr( $name ) . '" | 
| 438 | 438 | value="' . $value . '" ' . | 
| 439 | 439 | implode( ' ', $attributes ) . | 
| @@ -455,16 +455,16 @@ discard block | ||
| 455 | 455 | * @return string | 
| 456 | 456 | */ | 
| 457 | 457 |  	public function settings_save( $field, $echo = true ) { | 
| 458 | - $field['type'] = 'submit'; | |
| 459 | - $field['name'] = 'gform-settings-save'; | |
| 460 | - $field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton'; | |
| 458 | + $field[ 'type' ] = 'submit'; | |
| 459 | + $field[ 'name' ] = 'gform-settings-save'; | |
| 460 | + $field[ 'class' ] = isset( $field[ 'class' ] ) ? $field[ 'class' ] : 'button-primary gfbutton'; | |
| 461 | 461 | |
| 462 | 462 | if ( ! rgar( $field, 'value' ) ) | 
| 463 | - $field['value'] = __( 'Update Settings', 'gravityview' ); | |
| 463 | + $field[ 'value' ] = __( 'Update Settings', 'gravityview' ); | |
| 464 | 464 | |
| 465 | 465 | $output = $this->settings_submit( $field, false ); | 
| 466 | 466 | |
| 467 | -		if( $echo ) { | |
| 467 | +		if ( $echo ) { | |
| 468 | 468 | echo $output; | 
| 469 | 469 | } | 
| 470 | 470 | |
| @@ -481,8 +481,8 @@ discard block | ||
| 481 | 481 | parent::single_setting_label( $field ); | 
| 482 | 482 | |
| 483 | 483 | // Added by GravityView | 
| 484 | -		if ( isset( $field['description'] ) ) { | |
| 485 | - echo '<span class="description">'. $field['description'] .'</span>'; | |
| 484 | +		if ( isset( $field[ 'description' ] ) ) { | |
| 485 | + echo '<span class="description">' . $field[ 'description' ] . '</span>'; | |
| 486 | 486 | } | 
| 487 | 487 | |
| 488 | 488 | } | 
| @@ -544,11 +544,11 @@ discard block | ||
| 544 | 544 | |
| 545 | 545 | // If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response), | 
| 546 | 546 | // then we assume it's changed. If it's changed, unset the status and the previous response. | 
| 547 | -		if( $local_key !== $response_key ) { | |
| 547 | +		if ( $local_key !== $response_key ) { | |
| 548 | 548 | |
| 549 | - unset( $posted_settings['license_key_response'] ); | |
| 550 | - unset( $posted_settings['license_key_status'] ); | |
| 551 | -			GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); | |
| 549 | + unset( $posted_settings[ 'license_key_response' ] ); | |
| 550 | + unset( $posted_settings[ 'license_key_status' ] ); | |
| 551 | + GFCommon::add_error_message( __( 'The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); | |
| 552 | 552 | } | 
| 553 | 553 | |
| 554 | 554 | return $posted_settings; | 
| @@ -583,25 +583,25 @@ discard block | ||
| 583 | 583 | 'label' => __( 'License Key', 'gravityview' ), | 
| 584 | 584 | 'description' => __( 'Enter the license key that was sent to you on purchase. This enables plugin updates & support.', 'gravityview' ), | 
| 585 | 585 | 'type' => 'edd_license', | 
| 586 | -				'data-pending-text' => __('Verifying license…', 'gravityview'), | |
| 587 | - 'default_value' => $default_settings['license_key'], | |
| 586 | + 'data-pending-text' => __( 'Verifying license…', 'gravityview' ), | |
| 587 | + 'default_value' => $default_settings[ 'license_key' ], | |
| 588 | 588 | 'class' => ( '' == $this->get_app_setting( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key', | 
| 589 | 589 | ), | 
| 590 | 590 | array( | 
| 591 | 591 | 'name' => 'license_key_response', | 
| 592 | - 'default_value' => $default_settings['license_key_response'], | |
| 592 | + 'default_value' => $default_settings[ 'license_key_response' ], | |
| 593 | 593 | 'type' => 'hidden', | 
| 594 | 594 | ), | 
| 595 | 595 | array( | 
| 596 | 596 | 'name' => 'license_key_status', | 
| 597 | - 'default_value' => $default_settings['license_key_status'], | |
| 597 | + 'default_value' => $default_settings[ 'license_key_status' ], | |
| 598 | 598 | 'type' => 'hidden', | 
| 599 | 599 | ), | 
| 600 | 600 | array( | 
| 601 | 601 | 'name' => 'support-email', | 
| 602 | 602 | 'type' => 'text', | 
| 603 | 603 | 'validate' => 'email', | 
| 604 | - 'default_value' => $default_settings['support-email'], | |
| 604 | + 'default_value' => $default_settings[ 'support-email' ], | |
| 605 | 605 | 'label' => __( 'Support Email', 'gravityview' ), | 
| 606 | 606 | 'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ), | 
| 607 | 607 | 'class' => 'code regular-text', | 
| @@ -613,44 +613,44 @@ discard block | ||
| 613 | 613 | 'name' => 'support_port', | 
| 614 | 614 | 'type' => 'radio', | 
| 615 | 615 | 'label' => __( 'Show Support Port?', 'gravityview' ), | 
| 616 | - 'default_value' => $default_settings['support_port'], | |
| 616 | + 'default_value' => $default_settings[ 'support_port' ], | |
| 617 | 617 | 'horizontal' => 1, | 
| 618 | 618 | 'choices' => array( | 
| 619 | 619 | array( | 
| 620 | -						'label' => _x('Show', 'Setting: Show or Hide', 'gravityview'), | |
| 620 | + 'label' => _x( 'Show', 'Setting: Show or Hide', 'gravityview' ), | |
| 621 | 621 | 'value' => '1', | 
| 622 | 622 | ), | 
| 623 | 623 | array( | 
| 624 | -						'label' => _x('Hide', 'Setting: Show or Hide', 'gravityview'), | |
| 624 | + 'label' => _x( 'Hide', 'Setting: Show or Hide', 'gravityview' ), | |
| 625 | 625 | 'value' => '0', | 
| 626 | 626 | ), | 
| 627 | 627 | ), | 
| 628 | -				'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>', | |
| 628 | + '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>', | |
| 629 | 629 | 'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ), | 
| 630 | 630 | ), | 
| 631 | 631 | array( | 
| 632 | 632 | 'name' => 'no-conflict-mode', | 
| 633 | 633 | 'type' => 'radio', | 
| 634 | 634 | 'label' => __( 'No-Conflict Mode', 'gravityview' ), | 
| 635 | - 'default_value' => $default_settings['no-conflict-mode'], | |
| 635 | + 'default_value' => $default_settings[ 'no-conflict-mode' ], | |
| 636 | 636 | 'horizontal' => 1, | 
| 637 | 637 | 'choices' => array( | 
| 638 | 638 | array( | 
| 639 | -						'label' => _x('On', 'Setting: On or off', 'gravityview'), | |
| 639 | + 'label' => _x( 'On', 'Setting: On or off', 'gravityview' ), | |
| 640 | 640 | 'value' => '1', | 
| 641 | 641 | ), | 
| 642 | 642 | array( | 
| 643 | -						'label' => _x('Off', 'Setting: On or off', 'gravityview'), | |
| 643 | + 'label' => _x( 'Off', 'Setting: On or off', 'gravityview' ), | |
| 644 | 644 | 'value' => '0', | 
| 645 | 645 | ), | 
| 646 | 646 | ), | 
| 647 | -				'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'), | |
| 647 | + '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' ), | |
| 648 | 648 | ), | 
| 649 | 649 | array( | 
| 650 | 650 | 'name' => 'delete-on-uninstall', | 
| 651 | 651 | 'type' => 'radio', | 
| 652 | 652 | 'label' => __( 'Remove Data on Delete?', 'gravityview' ), | 
| 653 | - 'default_value' => $default_settings['delete-on-uninstall'], | |
| 653 | + 'default_value' => $default_settings[ 'delete-on-uninstall' ], | |
| 654 | 654 | 'horizontal' => 1, | 
| 655 | 655 | 'choices' => array( | 
| 656 | 656 | array( | 
| @@ -676,20 +676,20 @@ discard block | ||
| 676 | 676 | * @since 1.7.4 | 
| 677 | 677 | */ | 
| 678 | 678 |  		foreach ( $fields as &$field ) { | 
| 679 | -			$field['name']          = isset( $field['name'] ) ? $field['name'] : rgget('id', $field ); | |
| 680 | -			$field['label']         = isset( $field['label'] ) ? $field['label'] : rgget('title', $field ); | |
| 681 | -			$field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : rgget('default', $field ); | |
| 682 | -			$field['description']   = isset( $field['description'] ) ? $field['description'] : rgget('subtitle', $field ); | |
| 679 | + $field[ 'name' ] = isset( $field[ 'name' ] ) ? $field[ 'name' ] : rgget( 'id', $field ); | |
| 680 | + $field[ 'label' ] = isset( $field[ 'label' ] ) ? $field[ 'label' ] : rgget( 'title', $field ); | |
| 681 | + $field[ 'default_value' ] = isset( $field[ 'default_value' ] ) ? $field[ 'default_value' ] : rgget( 'default', $field ); | |
| 682 | + $field[ 'description' ] = isset( $field[ 'description' ] ) ? $field[ 'description' ] : rgget( 'subtitle', $field ); | |
| 683 | 683 | |
| 684 | -			if( $disabled_attribute ) { | |
| 685 | - $field['disabled'] = $disabled_attribute; | |
| 684 | +			if ( $disabled_attribute ) { | |
| 685 | + $field[ 'disabled' ] = $disabled_attribute; | |
| 686 | 686 | } | 
| 687 | 687 | } | 
| 688 | 688 | |
| 689 | 689 | |
| 690 | 690 | $sections = array( | 
| 691 | 691 | array( | 
| 692 | -                'description' =>      sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), | |
| 692 | + 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __( 'You are running GravityView version %s', 'gravityview' ), GravityView_Plugin::version ) ), | |
| 693 | 693 | 'fields' => $fields, | 
| 694 | 694 | ) | 
| 695 | 695 | ); | 
| @@ -700,8 +700,8 @@ discard block | ||
| 700 | 700 | 'type' => 'save', | 
| 701 | 701 | ); | 
| 702 | 702 | |
| 703 | -		if( $disabled_attribute ) { | |
| 704 | - $button['disabled'] = $disabled_attribute; | |
| 703 | +		if ( $disabled_attribute ) { | |
| 704 | + $button[ 'disabled' ] = $disabled_attribute; | |
| 705 | 705 | } | 
| 706 | 706 | |
| 707 | 707 | |
| @@ -721,20 +721,20 @@ discard block | ||
| 721 | 721 | // If there are extensions, add a section for them | 
| 722 | 722 |  		if ( ! empty( $extension_sections ) ) { | 
| 723 | 723 | |
| 724 | -			if( $disabled_attribute ) { | |
| 724 | +			if ( $disabled_attribute ) { | |
| 725 | 725 |  				foreach ( $extension_sections as &$section ) { | 
| 726 | -					foreach ( $section['fields'] as &$field ) { | |
| 727 | - $field['disabled'] = $disabled_attribute; | |
| 726 | +					foreach ( $section[ 'fields' ] as &$field ) { | |
| 727 | + $field[ 'disabled' ] = $disabled_attribute; | |
| 728 | 728 | } | 
| 729 | 729 | } | 
| 730 | 730 | } | 
| 731 | 731 | |
| 732 | - $k = count( $extension_sections ) - 1 ; | |
| 733 | - $extension_sections[ $k ]['fields'][] = $button; | |
| 732 | + $k = count( $extension_sections ) - 1; | |
| 733 | + $extension_sections[ $k ][ 'fields' ][ ] = $button; | |
| 734 | 734 | $sections = array_merge( $sections, $extension_sections ); | 
| 735 | 735 |  		} else { | 
| 736 | 736 | // add the 'update settings' button to the general section | 
| 737 | - $sections[0]['fields'][] = $button; | |
| 737 | + $sections[ 0 ][ 'fields' ][ ] = $button; | |
| 738 | 738 | } | 
| 739 | 739 | |
| 740 | 740 | return $sections; |