Completed
Pull Request — master (#605)
by Zack
05:22
created
gravityview.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -1,29 +1,29 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @file gravityview.php
4
- *
5
- * The GravityView plugin
6
- *
7
- * Create directories based on a Gravity Forms form, insert them using a shortcode, and modify how they output.
8
- *
9
- * @package   GravityView
10
- * @license   GPL2+
11
- * @author    Katz Web Services, Inc.
12
- * @link      http://gravityview.co
13
- * @copyright Copyright 2016, Katz Web Services, Inc.
14
- *
15
- * @wordpress-plugin
16
- * Plugin Name:       	GravityView
17
- * Plugin URI:        	http://gravityview.co
18
- * Description:       	Create directories based on a Gravity Forms form, insert them using a shortcode, and modify how they output.
19
- * Version:          	1.16
20
- * Author:            	Katz Web Services, Inc.
21
- * Author URI:        	http://www.katzwebservices.com
22
- * Text Domain:       	gravityview
23
- * License:           	GPLv2 or later
24
- * License URI: 		http://www.gnu.org/licenses/gpl-2.0.html
25
- * Domain Path:			/languages
26
- */
3
+	 * @file gravityview.php
4
+	 *
5
+	 * The GravityView plugin
6
+	 *
7
+	 * Create directories based on a Gravity Forms form, insert them using a shortcode, and modify how they output.
8
+	 *
9
+	 * @package   GravityView
10
+	 * @license   GPL2+
11
+	 * @author    Katz Web Services, Inc.
12
+	 * @link      http://gravityview.co
13
+	 * @copyright Copyright 2016, Katz Web Services, Inc.
14
+	 *
15
+	 * @wordpress-plugin
16
+	 * Plugin Name:       	GravityView
17
+	 * Plugin URI:        	http://gravityview.co
18
+	 * Description:       	Create directories based on a Gravity Forms form, insert them using a shortcode, and modify how they output.
19
+	 * Version:          	1.16
20
+	 * Author:            	Katz Web Services, Inc.
21
+	 * Author URI:        	http://www.katzwebservices.com
22
+	 * Text Domain:       	gravityview
23
+	 * License:           	GPLv2 or later
24
+	 * License URI: 		http://www.gnu.org/licenses/gpl-2.0.html
25
+	 * Domain Path:			/languages
26
+	 */
27 27
 
28 28
 /** If this file is called directly, abort. */
29 29
 if ( ! defined( 'ABSPATH' ) ) {
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
 		include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' );
312 312
 
313 313
 
314
-        /**
315
-         * When an entry is created, check if we need to update the custom slug meta
316
-         * todo: move this to its own class..
317
-         */
318
-        add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
314
+		/**
315
+		 * When an entry is created, check if we need to update the custom slug meta
316
+		 * todo: move this to its own class..
317
+		 */
318
+		add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
319 319
 
320 320
 		/**
321 321
 		 * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded
@@ -345,34 +345,34 @@  discard block
 block discarded – undo
345 345
 
346 346
 	/** DEBUG */
347 347
 
348
-    /**
349
-     * Logs messages using Gravity Forms logging add-on
350
-     * @param  string $message log message
351
-     * @param mixed $data Additional data to display
352
-     * @return void
353
-     */
354
-    public static function log_debug( $message, $data = null ){
355
-	    /**
356
-	     * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
357
-	     * @param string $message Message to display
358
-	     * @param mixed $data Supporting data to print alongside it
359
-	     */
360
-    	do_action( 'gravityview_log_debug', $message, $data );
361
-    }
362
-
363
-    /**
364
-     * Logs messages using Gravity Forms logging add-on
365
-     * @param  string $message log message
366
-     * @return void
367
-     */
368
-    public static function log_error( $message, $data = null ){
369
-	    /**
370
-	     * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
371
-	     * @param string $message Error message to display
372
-	     * @param mixed $data Supporting data to print alongside it
373
-	     */
374
-    	do_action( 'gravityview_log_error', $message, $data );
375
-    }
348
+	/**
349
+	 * Logs messages using Gravity Forms logging add-on
350
+	 * @param  string $message log message
351
+	 * @param mixed $data Additional data to display
352
+	 * @return void
353
+	 */
354
+	public static function log_debug( $message, $data = null ){
355
+		/**
356
+		 * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
357
+		 * @param string $message Message to display
358
+		 * @param mixed $data Supporting data to print alongside it
359
+		 */
360
+		do_action( 'gravityview_log_debug', $message, $data );
361
+	}
362
+
363
+	/**
364
+	 * Logs messages using Gravity Forms logging add-on
365
+	 * @param  string $message log message
366
+	 * @return void
367
+	 */
368
+	public static function log_error( $message, $data = null ){
369
+		/**
370
+		 * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output
371
+		 * @param string $message Error message to display
372
+		 * @param mixed $data Supporting data to print alongside it
373
+		 */
374
+		do_action( 'gravityview_log_error', $message, $data );
375
+	}
376 376
 
377 377
 } // end class GravityView_Plugin
378 378
 
Please login to merge, or discard this patch.
includes/class-gravityview-merge-tags.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@
 block discarded – undo
122 122
 
123 123
 		$atts = array(
124 124
 			'format' => self::get_format_from_modifiers( $exploded, false ),
125
-		    'human' => in_array( 'human', $exploded ), // {date_created:human}
125
+			'human' => in_array( 'human', $exploded ), // {date_created:human}
126 126
 			'diff' => in_array( 'diff', $exploded ), // {date_created:diff}
127 127
 			'raw' => in_array( 'raw', $exploded ), // {date_created:raw}
128 128
 			'timestamp' => in_array( 'timestamp', $exploded ), // {date_created:timestamp}
Please login to merge, or discard this patch.
includes/widgets/search-widget/templates/search-field-link.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Display the search LINK input field
4
- *
5
- * @see class-search-widget.php
6
- */
3
+			 * Display the search LINK input field
4
+			 *
5
+			 * @see class-search-widget.php
6
+			 */
7 7
 
8 8
 $gravityview_view = GravityView_View::getInstance();
9 9
 $view_id = $gravityview_view->getViewId();
@@ -39,22 +39,22 @@  discard block
 block discarded – undo
39 39
 
40 40
         <?php
41 41
 
42
-        $search_value = rgget( $search_field['name'] );
42
+		$search_value = rgget( $search_field['name'] );
43 43
 
44
-        foreach ( $search_field['choices'] as $k => $choice ) {
44
+		foreach ( $search_field['choices'] as $k => $choice ) {
45 45
 
46
-            if ( 0 != $k ) {
47
-                echo esc_html( $links_sep );
48
-            }
46
+			if ( 0 != $k ) {
47
+				echo esc_html( $links_sep );
48
+			}
49 49
 
50
-            $active = ( '' !== $search_value && in_array( $search_value, array( $choice['text'], $choice['value'] ) ) ) ? ' class="active"' : false;
50
+			$active = ( '' !== $search_value && in_array( $search_value, array( $choice['text'], $choice['value'] ) ) ) ? ' class="active"' : false;
51 51
 
52
-            if ( $active ) {
53
-                $link = remove_query_arg( array( 'pagenum', $search_field['name'] ), $base_url );
54
-            } else {
55
-                $link = add_query_arg( array( $search_field['name'] => urlencode( $choice['value'] ) ), remove_query_arg( array('pagenum'), $base_url ) );
56
-            }
57
-            ?>
52
+			if ( $active ) {
53
+				$link = remove_query_arg( array( 'pagenum', $search_field['name'] ), $base_url );
54
+			} else {
55
+				$link = add_query_arg( array( $search_field['name'] => urlencode( $choice['value'] ) ), remove_query_arg( array('pagenum'), $base_url ) );
56
+			}
57
+			?>
58 58
 
59 59
 			<a href="<?php echo esc_url_raw( $link ); ?>" <?php echo $active; ?>><?php echo esc_html( $choice['text'] ); ?></a>
60 60
 
Please login to merge, or discard this patch.
includes/widgets/search-widget/templates/search-field-search_all.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Display the search all input box
4
- *
5
- * @see class-search-widget.php
6
- */
3
+			 * Display the search all input box
4
+			 *
5
+			 * @see class-search-widget.php
6
+			 */
7 7
 
8 8
 $gravityview_view = GravityView_View::getInstance();
9 9
 $view_id = $gravityview_view->getViewId();
Please login to merge, or discard this patch.
includes/admin/metaboxes/views/sort-filter.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package GravityView
4
- * @subpackage Gravityview/admin/metaboxes/partials
5
- * @global WP_Post $post
6
- */
3
+		 * @package GravityView
4
+		 * @subpackage Gravityview/admin/metaboxes/partials
5
+		 * @global WP_Post $post
6
+		 */
7 7
 global $post;
8 8
 
9 9
 $curr_form = gravityview_get_form_id( $post->ID );
Please login to merge, or discard this patch.
includes/class-admin-approve-entries.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @file class-admin-approve-entries.php
4
- * @package   GravityView
5
- * @license   GPL2+
6
- * @author    Katz Web Services, Inc.
7
- * @link      http://gravityview.co
8
- * @copyright Copyright 2014, Katz Web Services, Inc.
9
- *
10
- * @since 1.0.0
11
- */
3
+	 * @file class-admin-approve-entries.php
4
+	 * @package   GravityView
5
+	 * @license   GPL2+
6
+	 * @author    Katz Web Services, Inc.
7
+	 * @link      http://gravityview.co
8
+	 * @copyright Copyright 2014, Katz Web Services, Inc.
9
+	 *
10
+	 * @since 1.0.0
11
+	 */
12 12
 
13 13
 
14 14
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 
322 322
 			if( class_exists( 'GravityView_Entry_Notes' ) ){
323 323
 				global $current_user;
324
-      			get_currentuserinfo();
324
+	  			get_currentuserinfo();
325 325
 				GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $current_user->display_name, $note );
326 326
 			}
327 327
 
@@ -356,12 +356,12 @@  discard block
 block discarded – undo
356 356
 
357 357
 		$approvedcolumn = self::get_approved_column( $form['id'] );
358 358
 
359
-        /**
360
-         * If the form doesn't contain the approve field, don't assume anything.
361
-         */
362
-        if( empty( $approvedcolumn ) ) {
363
-            return;
364
-        }
359
+		/**
360
+		 * If the form doesn't contain the approve field, don't assume anything.
361
+		 */
362
+		if( empty( $approvedcolumn ) ) {
363
+			return;
364
+		}
365 365
 
366 366
 		$entry = GFAPI::get_entry( $entry_id );
367 367
 
@@ -474,17 +474,17 @@  discard block
 block discarded – undo
474 474
 	 */
475 475
 	static public function get_approved_column( $form ) {
476 476
 
477
-        if( empty( $form ) ) {
478
-            return null;
479
-        }
477
+		if( empty( $form ) ) {
478
+			return null;
479
+		}
480 480
 
481
-        if( !is_array( $form ) ) {
482
-            $form = GVCommon::get_form( $form );
483
-        }
481
+		if( !is_array( $form ) ) {
482
+			$form = GVCommon::get_form( $form );
483
+		}
484 484
 
485 485
 		foreach( $form['fields'] as $key => $field ) {
486 486
 
487
-            $field = (array) $field;
487
+			$field = (array) $field;
488 488
 
489 489
 			if( !empty( $field['gravityview_approved'] ) ) {
490 490
 				if( !empty($field['inputs'][0]['id']) ) {
@@ -492,14 +492,14 @@  discard block
 block discarded – undo
492 492
 				}
493 493
 			}
494 494
 
495
-            // Note: This is just for backward compatibility from GF Directory plugin and old GV versions - when using i18n it may not work..
496
-            if( 'checkbox' == $field['type'] && isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) {
497
-                foreach ( $field['inputs'] as $key2 => $input ) {
498
-                    if ( strtolower( $input['label'] ) == 'approved' ) {
499
-                        return $input['id'];
500
-                    }
501
-                }
502
-            }
495
+			// Note: This is just for backward compatibility from GF Directory plugin and old GV versions - when using i18n it may not work..
496
+			if( 'checkbox' == $field['type'] && isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) {
497
+				foreach ( $field['inputs'] as $key2 => $input ) {
498
+					if ( strtolower( $input['label'] ) == 'approved' ) {
499
+						return $input['id'];
500
+					}
501
+				}
502
+			}
503 503
 		}
504 504
 
505 505
 		return null;
Please login to merge, or discard this patch.
includes/extensions/edit-entry/class-edit-entry-user-registration.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * GravityView Edit Entry - Sync User Registration (when using the GF User Registration Add-on)
4
- *
5
- * @since 1.11
6
- * @package   GravityView
7
- * @license   GPL2+
8
- * @author    Katz Web Services, Inc.
9
- * @link      http://gravityview.co
10
- * @copyright Copyright 2015, Katz Web Services, Inc.
11
- */
3
+	 * GravityView Edit Entry - Sync User Registration (when using the GF User Registration Add-on)
4
+	 *
5
+	 * @since 1.11
6
+	 * @package   GravityView
7
+	 * @license   GPL2+
8
+	 * @author    Katz Web Services, Inc.
9
+	 * @link      http://gravityview.co
10
+	 * @copyright Copyright 2015, Katz Web Services, Inc.
11
+	 */
12 12
 
13 13
 if ( ! defined( 'WPINC' ) ) {
14
-    die;
14
+	die;
15 15
 }
16 16
 
17 17
 /**
@@ -22,237 +22,237 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @var GravityView_Edit_Entry
24 24
 	 */
25
-    protected $loader;
25
+	protected $loader;
26 26
 
27
-    /**
28
-     * @var WP_User|null Temporary storage used by restore_user_details()
29
-     */
30
-    private $_user_before_update = null;
27
+	/**
28
+	 * @var WP_User|null Temporary storage used by restore_user_details()
29
+	 */
30
+	private $_user_before_update = null;
31 31
 
32
-    function __construct( GravityView_Edit_Entry $loader ) {
33
-        $this->loader = $loader;
34
-    }
32
+	function __construct( GravityView_Edit_Entry $loader ) {
33
+		$this->loader = $loader;
34
+	}
35 35
 
36 36
 	/**
37 37
 	 * @since 1.11
38 38
 	 */
39 39
 	public function load() {
40 40
 
41
-        /**
42
-	     * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated?
43
-	     * @since 1.11
44
-	     * @param boolean $boolean Whether to trigger update on user registration (default: true)
45
-	     */
46
-        if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) {
47
-            add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 );
48
-
49
-            // last resort in case the current user display name don't match any of the defaults
50
-            add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 );
51
-        }
52
-    }
53
-
54
-    /**
55
-     * Update the WordPress user profile based on the GF User Registration create feed
56
-     *
57
-     * @since 1.11
58
-     *
59
-     * @param array $form Gravity Forms form array
60
-     * @param string $entry_id Gravity Forms entry ID
61
-     * @return void
62
-     */
63
-    public function update_user( $form = array(), $entry_id = 0 ) {
64
-
65
-        if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) {
66
-            return;
67
-        }
68
-
69
-        $entry = GFAPI::get_entry( $entry_id );
70
-
71
-	    /**
72
-	     * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on
73
-	     * @since 1.11
74
-	     * @param array $entry Gravity Forms entry
75
-	     * @param array $form Gravity Forms form
76
-	     */
77
-        $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form );
78
-
79
-        /**
80
-         * @since 1.14
81
-         */
82
-        $config = GFUser::get_active_config( $form, $entry );
83
-
84
-        /**
85
-         * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed
86
-         * @since 1.15
87
-         * @param[in,out] boolean $preserve_role Preserve current user role Default: true
88
-         * @param[in] array $config Gravity Forms User Registration feed configuration for the form
89
-         * @param[in] array $form Gravity Forms form array
90
-         * @param[in] array $entry Gravity Forms entry being edited
91
-         */
92
-        $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry );
93
-
94
-        if( $preserve_role ) {
95
-            $config['meta']['role'] = 'gfur_preserve_role';
96
-        }
97
-
98
-        /**
99
-         * Make sure the current display name is not changed with the update user method.
100
-         * @since 1.15
101
-         */
102
-        $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] );
103
-
104
-
105
-        /**
106
-         * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration
107
-         * @since 1.14
108
-         * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form
109
-         * @param[in] array $form Gravity Forms form array
110
-         * @param[in] array $entry Gravity Forms entry being edited
111
-         */
112
-        $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry );
113
-
114
-        $is_create_feed = ( $config && rgars( $config, 'meta/feed_type') === 'create' );
115
-
116
-        // Only update if it's a create feed
117
-        if( ! $is_create_feed ) {
118
-            return;
119
-        }
120
-
121
-        // The priority is set to 3 so that default priority (10) will still override it
122
-        add_filter( 'send_password_change_email', '__return_false', 3 );
123
-        add_filter( 'send_email_change_email', '__return_false', 3 );
124
-
125
-        // Trigger the User Registration update user method
126
-        GFUser::update_user( $entry, $form, $config );
127
-
128
-        remove_filter( 'send_password_change_email', '__return_false', 3 );
129
-        remove_filter( 'send_email_change_email', '__return_false', 3 );
130
-
131
-    }
132
-
133
-    /**
134
-     * Calculate the user display name format
135
-     *
136
-     * @since 1.15
137
-     *
138
-     * @param int $user_id WP User ID
139
-     * @return string Display name format as used inside Gravity Forms User Registration
140
-     */
141
-    public function match_current_display_name( $user_id ) {
142
-
143
-        $user = get_userdata( $user_id );
144
-
145
-        $names = $this->generate_display_names( $user );
146
-
147
-        $format = array_search( $user->display_name, $names, true );
148
-
149
-        // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support)
150
-        //   trigger last resort method at the 'gform_user_updated' hook
151
-        if( false === $format || 'nickname' === $format ) {
152
-            $this->_user_before_update = $user;
153
-            $format = 'nickname';
154
-        }
155
-
156
-        return $format;
157
-
158
-    }
159
-
160
-    /**
161
-     * Generate an array of all the user display names possibilities
162
-     *
163
-     * @since 1.15
164
-     *
165
-     * @param object $profileuser WP_User object
166
-     * @return array List all the possible display names for a certain User object
167
-     */
168
-    public function generate_display_names( $profileuser ) {
169
-
170
-        $public_display = array();
171
-        $public_display['nickname']  = $profileuser->nickname;
172
-        $public_display['username']  = $profileuser->user_login;
173
-
174
-        if ( !empty($profileuser->first_name) )
175
-            $public_display['firstname'] = $profileuser->first_name;
176
-
177
-        if ( !empty($profileuser->last_name) )
178
-            $public_display['lastname'] = $profileuser->last_name;
179
-
180
-        if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
181
-            $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
182
-            $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
183
-        }
184
-
185
-        $public_display = array_map( 'trim', $public_display );
186
-        $public_display = array_unique( $public_display );
187
-
188
-        return $public_display;
189
-    }
190
-
191
-
192
-    /**
193
-     * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon
194
-     *
195
-     * @see GFUser::update_user()
196
-     * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon
197
-     * @param array $config Gravity Forms User Registration Addon form feed configuration
198
-     * @param array $entry The Gravity Forms entry that was just updated
199
-     * @param string $password User password
200
-     * @return void
201
-     */
202
-    public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) {
203
-
204
-        /**
205
-         * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry.
206
-         * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed
207
-         * @since 1.14.4
208
-         * @param boolean $restore_display_name Restore Display Name? Default: true
209
-         */
210
-        $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true );
211
-
212
-        $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' );
213
-
214
-        /**
215
-         * Don't restore display name:
216
-         *   - either disabled,
217
-         *   - or it is an Update feed (we only care about Create feed)
218
-         *   - or we don't need as we found the correct format before updating user.
219
-         * @since 1.14.4
220
-         */
221
-        if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) {
222
-            return;
223
-        }
224
-
225
-        $user_after_update = get_userdata( $user_id );
226
-
227
-        $restored_user = $user_after_update;
228
-
229
-	    // Restore previous display_name
230
-        $restored_user->display_name = $this->_user_before_update->display_name;
231
-
232
-	    // Don't have WP update the password.
233
-	    unset( $restored_user->data->user_pass, $restored_user->user_pass );
234
-
235
-        /**
236
-         * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView
237
-         * @since 1.14
238
-         * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user()
239
-         * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration
240
-         * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration
241
-         * @param array   $entry The Gravity Forms entry that was just updated
242
-         */
243
-        $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry );
244
-
245
-        $updated = wp_update_user( $restored_user );
246
-
247
-        if( is_wp_error( $updated ) ) {
248
-            do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated );
249
-        } else {
250
-            do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) );
251
-        }
252
-
253
-        $this->_user_before_update = null;
254
-
255
-        unset( $updated, $restored_user, $user_after_update );
256
-    }
41
+		/**
42
+		 * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated?
43
+		 * @since 1.11
44
+		 * @param boolean $boolean Whether to trigger update on user registration (default: true)
45
+		 */
46
+		if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) {
47
+			add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 );
48
+
49
+			// last resort in case the current user display name don't match any of the defaults
50
+			add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 );
51
+		}
52
+	}
53
+
54
+	/**
55
+	 * Update the WordPress user profile based on the GF User Registration create feed
56
+	 *
57
+	 * @since 1.11
58
+	 *
59
+	 * @param array $form Gravity Forms form array
60
+	 * @param string $entry_id Gravity Forms entry ID
61
+	 * @return void
62
+	 */
63
+	public function update_user( $form = array(), $entry_id = 0 ) {
64
+
65
+		if( !class_exists( 'GFAPI' ) || !class_exists( 'GFUser' ) || empty( $entry_id ) ) {
66
+			return;
67
+		}
68
+
69
+		$entry = GFAPI::get_entry( $entry_id );
70
+
71
+		/**
72
+		 * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on
73
+		 * @since 1.11
74
+		 * @param array $entry Gravity Forms entry
75
+		 * @param array $form Gravity Forms form
76
+		 */
77
+		$entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form );
78
+
79
+		/**
80
+		 * @since 1.14
81
+		 */
82
+		$config = GFUser::get_active_config( $form, $entry );
83
+
84
+		/**
85
+		 * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed
86
+		 * @since 1.15
87
+		 * @param[in,out] boolean $preserve_role Preserve current user role Default: true
88
+		 * @param[in] array $config Gravity Forms User Registration feed configuration for the form
89
+		 * @param[in] array $form Gravity Forms form array
90
+		 * @param[in] array $entry Gravity Forms entry being edited
91
+		 */
92
+		$preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry );
93
+
94
+		if( $preserve_role ) {
95
+			$config['meta']['role'] = 'gfur_preserve_role';
96
+		}
97
+
98
+		/**
99
+		 * Make sure the current display name is not changed with the update user method.
100
+		 * @since 1.15
101
+		 */
102
+		$config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] );
103
+
104
+
105
+		/**
106
+		 * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration
107
+		 * @since 1.14
108
+		 * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form
109
+		 * @param[in] array $form Gravity Forms form array
110
+		 * @param[in] array $entry Gravity Forms entry being edited
111
+		 */
112
+		$config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry );
113
+
114
+		$is_create_feed = ( $config && rgars( $config, 'meta/feed_type') === 'create' );
115
+
116
+		// Only update if it's a create feed
117
+		if( ! $is_create_feed ) {
118
+			return;
119
+		}
120
+
121
+		// The priority is set to 3 so that default priority (10) will still override it
122
+		add_filter( 'send_password_change_email', '__return_false', 3 );
123
+		add_filter( 'send_email_change_email', '__return_false', 3 );
124
+
125
+		// Trigger the User Registration update user method
126
+		GFUser::update_user( $entry, $form, $config );
127
+
128
+		remove_filter( 'send_password_change_email', '__return_false', 3 );
129
+		remove_filter( 'send_email_change_email', '__return_false', 3 );
130
+
131
+	}
132
+
133
+	/**
134
+	 * Calculate the user display name format
135
+	 *
136
+	 * @since 1.15
137
+	 *
138
+	 * @param int $user_id WP User ID
139
+	 * @return string Display name format as used inside Gravity Forms User Registration
140
+	 */
141
+	public function match_current_display_name( $user_id ) {
142
+
143
+		$user = get_userdata( $user_id );
144
+
145
+		$names = $this->generate_display_names( $user );
146
+
147
+		$format = array_search( $user->display_name, $names, true );
148
+
149
+		// In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support)
150
+		//   trigger last resort method at the 'gform_user_updated' hook
151
+		if( false === $format || 'nickname' === $format ) {
152
+			$this->_user_before_update = $user;
153
+			$format = 'nickname';
154
+		}
155
+
156
+		return $format;
157
+
158
+	}
159
+
160
+	/**
161
+	 * Generate an array of all the user display names possibilities
162
+	 *
163
+	 * @since 1.15
164
+	 *
165
+	 * @param object $profileuser WP_User object
166
+	 * @return array List all the possible display names for a certain User object
167
+	 */
168
+	public function generate_display_names( $profileuser ) {
169
+
170
+		$public_display = array();
171
+		$public_display['nickname']  = $profileuser->nickname;
172
+		$public_display['username']  = $profileuser->user_login;
173
+
174
+		if ( !empty($profileuser->first_name) )
175
+			$public_display['firstname'] = $profileuser->first_name;
176
+
177
+		if ( !empty($profileuser->last_name) )
178
+			$public_display['lastname'] = $profileuser->last_name;
179
+
180
+		if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
181
+			$public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
182
+			$public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
183
+		}
184
+
185
+		$public_display = array_map( 'trim', $public_display );
186
+		$public_display = array_unique( $public_display );
187
+
188
+		return $public_display;
189
+	}
190
+
191
+
192
+	/**
193
+	 * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon
194
+	 *
195
+	 * @see GFUser::update_user()
196
+	 * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon
197
+	 * @param array $config Gravity Forms User Registration Addon form feed configuration
198
+	 * @param array $entry The Gravity Forms entry that was just updated
199
+	 * @param string $password User password
200
+	 * @return void
201
+	 */
202
+	public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) {
203
+
204
+		/**
205
+		 * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry.
206
+		 * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed
207
+		 * @since 1.14.4
208
+		 * @param boolean $restore_display_name Restore Display Name? Default: true
209
+		 */
210
+		$restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true );
211
+
212
+		$is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' );
213
+
214
+		/**
215
+		 * Don't restore display name:
216
+		 *   - either disabled,
217
+		 *   - or it is an Update feed (we only care about Create feed)
218
+		 *   - or we don't need as we found the correct format before updating user.
219
+		 * @since 1.14.4
220
+		 */
221
+		if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) {
222
+			return;
223
+		}
224
+
225
+		$user_after_update = get_userdata( $user_id );
226
+
227
+		$restored_user = $user_after_update;
228
+
229
+		// Restore previous display_name
230
+		$restored_user->display_name = $this->_user_before_update->display_name;
231
+
232
+		// Don't have WP update the password.
233
+		unset( $restored_user->data->user_pass, $restored_user->user_pass );
234
+
235
+		/**
236
+		 * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView
237
+		 * @since 1.14
238
+		 * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user()
239
+		 * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration
240
+		 * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration
241
+		 * @param array   $entry The Gravity Forms entry that was just updated
242
+		 */
243
+		$restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry );
244
+
245
+		$updated = wp_update_user( $restored_user );
246
+
247
+		if( is_wp_error( $updated ) ) {
248
+			do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated );
249
+		} else {
250
+			do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) );
251
+		}
252
+
253
+		$this->_user_before_update = null;
254
+
255
+		unset( $updated, $restored_user, $user_after_update );
256
+	}
257 257
 
258 258
 } //end class
Please login to merge, or discard this patch.
includes/presets/event-listings/class-gravityview-preset-event-listings.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * GravityView preset template
4
- *
5
- * @file class-gravityview-preset-event-listings.php
6
- * @package   GravityView
7
- * @license   GPL2+
8
- * @author    Katz Web Services, Inc.
9
- * @link      http://gravityview.co
10
- * @copyright Copyright 2015, Katz Web Services, Inc.
11
- *
12
- * @since 1.15
13
- */
3
+	 * GravityView preset template
4
+	 *
5
+	 * @file class-gravityview-preset-event-listings.php
6
+	 * @package   GravityView
7
+	 * @license   GPL2+
8
+	 * @author    Katz Web Services, Inc.
9
+	 * @link      http://gravityview.co
10
+	 * @copyright Copyright 2015, Katz Web Services, Inc.
11
+	 *
12
+	 * @since 1.15
13
+	 */
14 14
 
15 15
 class GravityView_Preset_Event_Listings extends GravityView_Default_Template_List {
16 16
 
Please login to merge, or discard this patch.
includes/class-api.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -146,20 +146,20 @@  discard block
 block discarded – undo
146 146
 
147 147
 		if( !empty( $field['custom_class'] ) ) {
148 148
 
149
-            $custom_class = $field['custom_class'];
149
+			$custom_class = $field['custom_class'];
150 150
 
151
-            if( !empty( $entry ) ) {
151
+			if( !empty( $entry ) ) {
152 152
 
153
-                // We want the merge tag to be formatted as a class. The merge tag may be
154
-                // replaced by a multiple-word value that should be output as a single class.
155
-                // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager`
156
-                add_filter('gform_merge_tag_filter', 'sanitize_html_class');
153
+				// We want the merge tag to be formatted as a class. The merge tag may be
154
+				// replaced by a multiple-word value that should be output as a single class.
155
+				// "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager`
156
+				add_filter('gform_merge_tag_filter', 'sanitize_html_class');
157 157
 
158
-                $custom_class = self::replace_variables( $custom_class, $form, $entry);
158
+				$custom_class = self::replace_variables( $custom_class, $form, $entry);
159 159
 
160
-                // And then we want life to return to normal
161
-                remove_filter('gform_merge_tag_filter', 'sanitize_html_class');
162
-            }
160
+				// And then we want life to return to normal
161
+				remove_filter('gform_merge_tag_filter', 'sanitize_html_class');
162
+			}
163 163
 
164 164
 			// And now we want the spaces to be handled nicely.
165 165
 			$classes[] = gravityview_sanitize_html_class( $custom_class );
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 			'format' => $format,
293 293
 			'entry' => $entry,
294 294
 			'field_type' => $field_type, /** {@since 1.6} */
295
-		    'field_path' => $field_path, /** {@since 1.16} */
295
+			'field_path' => $field_path, /** {@since 1.16} */
296 296
 		));
297 297
 
298 298
 		if( ! empty( $field_path ) ) {
@@ -603,29 +603,29 @@  discard block
 block discarded – undo
603 603
 		return sanitize_title( $slug );
604 604
 	}
605 605
 
606
-    /**
607
-     * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta
608
-     *
609
-     * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
610
-     *
611
-     * @param $entry array Gravity Forms entry object
612
-     * @param $form array Gravity Forms form object
613
-     */
614
-    public static function entry_create_custom_slug( $entry, $form ) {
615
-        /**
616
-         * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta
617
-         * @param boolean $custom Should we process the custom entry slug?
618
-         */
619
-        $custom = apply_filters( 'gravityview_custom_entry_slug', false );
620
-        if( $custom ) {
621
-            // create the gravityview_unique_id and save it
606
+	/**
607
+	 * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta
608
+	 *
609
+	 * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
610
+	 *
611
+	 * @param $entry array Gravity Forms entry object
612
+	 * @param $form array Gravity Forms form object
613
+	 */
614
+	public static function entry_create_custom_slug( $entry, $form ) {
615
+		/**
616
+		 * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta
617
+		 * @param boolean $custom Should we process the custom entry slug?
618
+		 */
619
+		$custom = apply_filters( 'gravityview_custom_entry_slug', false );
620
+		if( $custom ) {
621
+			// create the gravityview_unique_id and save it
622 622
 
623
-            // Get the entry hash
624
-            $hash = self::get_custom_entry_slug( $entry['id'], $entry );
625
-            gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash );
623
+			// Get the entry hash
624
+			$hash = self::get_custom_entry_slug( $entry['id'], $entry );
625
+			gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash );
626 626
 
627
-        }
628
-    }
627
+		}
628
+	}
629 629
 
630 630
 
631 631
 
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 
890 890
 			// If there was an error, continue to the next term.
891 891
 			if ( is_wp_error( $term_link ) ) {
892
-			    continue;
892
+				continue;
893 893
 			}
894 894
 
895 895
 			$output[] = gravityview_get_link( $term_link, esc_html( $term->name ) );
Please login to merge, or discard this patch.