@@ -41,22 +41,22 @@ |
||
| 41 | 41 | |
| 42 | 42 | <?php |
| 43 | 43 | |
| 44 | - $search_value = \GV\Utils::_GET( $search_field['name'] ); |
|
| 44 | + $search_value = \GV\Utils::_GET( $search_field['name'] ); |
|
| 45 | 45 | |
| 46 | - foreach ( $search_field['choices'] as $k => $choice ) { |
|
| 46 | + foreach ( $search_field['choices'] as $k => $choice ) { |
|
| 47 | 47 | |
| 48 | - if ( 0 != $k ) { |
|
| 49 | - echo esc_html( $links_sep ); |
|
| 50 | - } |
|
| 48 | + if ( 0 != $k ) { |
|
| 49 | + echo esc_html( $links_sep ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $active = ( '' !== $search_value && in_array( $search_value, array( $choice['text'], $choice['value'] ) ) ) ? ' class="active"' : false; |
|
| 52 | + $active = ( '' !== $search_value && in_array( $search_value, array( $choice['text'], $choice['value'] ) ) ) ? ' class="active"' : false; |
|
| 53 | 53 | |
| 54 | - if ( $active ) { |
|
| 55 | - $link = remove_query_arg( array( 'pagenum', $search_field['name'] ), $base_url ); |
|
| 56 | - } else { |
|
| 57 | - $link = add_query_arg( array( $search_field['name'] => urlencode( $choice['value'] ) ), remove_query_arg( array('pagenum'), $base_url ) ); |
|
| 58 | - } |
|
| 59 | - ?> |
|
| 54 | + if ( $active ) { |
|
| 55 | + $link = remove_query_arg( array( 'pagenum', $search_field['name'] ), $base_url ); |
|
| 56 | + } else { |
|
| 57 | + $link = add_query_arg( array( $search_field['name'] => urlencode( $choice['value'] ) ), remove_query_arg( array('pagenum'), $base_url ) ); |
|
| 58 | + } |
|
| 59 | + ?> |
|
| 60 | 60 | |
| 61 | 61 | <a href="<?php echo esc_url_raw( $link ); ?>" <?php echo $active; ?>><?php echo esc_html( $choice['text'] ); ?></a> |
| 62 | 62 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * @action `gravityview_search_widget_field_before` Before each search input is rendered (other than the submit button) |
| 33 | 33 | * @param GravityView_Widget_Search $this GravityView Widget instance |
| 34 | - * @param array $search_field |
|
| 34 | + * @param array $search_field |
|
| 35 | 35 | */ |
| 36 | 36 | do_action( 'gravityview_search_widget_field_before', $this, $search_field ); |
| 37 | 37 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @action `gravityview_search_widget_field_after` After each search input is rendered (other than the submit button) |
| 48 | 48 | * @param GravityView_Widget_Search $this GravityView Widget instance |
| 49 | - * @param array $search_field |
|
| 49 | + * @param array $search_field |
|
| 50 | 50 | */ |
| 51 | 51 | do_action( 'gravityview_search_widget_field_after', $this, $search_field ); |
| 52 | 52 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | do_action( 'gravityview_search_widget_fields_after', $this ); |
| 59 | 59 | |
| 60 | 60 | if( $has_inputs ) { |
| 61 | - $this->render( 'search-field', 'submit', false ); |
|
| 62 | - } |
|
| 61 | + $this->render( 'search-field', 'submit', false ); |
|
| 62 | + } |
|
| 63 | 63 | ?> |
| 64 | 64 | </form> |
@@ -28,13 +28,13 @@ |
||
| 28 | 28 | |
| 29 | 29 | $show_mt = $this->show_merge_tags(); |
| 30 | 30 | |
| 31 | - if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 32 | - $class .= ' merge-tag-support mt-position-right '; |
|
| 31 | + if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 32 | + $class .= ' merge-tag-support mt-position-right '; |
|
| 33 | 33 | |
| 34 | - if( empty( $this->field['show_all_fields'] ) ) { |
|
| 35 | - $class .= ' mt-hide_all_fields '; |
|
| 36 | - } |
|
| 37 | - } |
|
| 34 | + if( empty( $this->field['show_all_fields'] ) ) { |
|
| 35 | + $class .= ' mt-hide_all_fields '; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | $class .= \GV\Utils::get( $this->field, 'class' ); |
| 39 | 39 | $placeholder = \GV\Utils::get( $this->field, 'placeholder' ); |
| 40 | 40 | $rows = \GV\Utils::get( $this->field, 'rows', 5 ); |
@@ -28,11 +28,11 @@ |
||
| 28 | 28 | |
| 29 | 29 | $show_mt = $this->show_merge_tags(); |
| 30 | 30 | |
| 31 | - if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 32 | - $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
|
| 33 | - } |
|
| 34 | - $class .= \GV\Utils::get( $this->field, 'class', 'widefat' ); |
|
| 35 | - $placeholder = \GV\Utils::get( $this->field, 'placeholder' ); |
|
| 31 | + if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 32 | + $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
|
| 33 | + } |
|
| 34 | + $class .= \GV\Utils::get( $this->field, 'class', 'widefat' ); |
|
| 35 | + $placeholder = \GV\Utils::get( $this->field, 'placeholder' ); |
|
| 36 | 36 | ?> |
| 37 | 37 | <input name="<?php echo esc_attr( $this->name ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" id="<?php echo $this->get_field_id(); ?>" type="text" value="<?php echo esc_attr( $this->value ); ?>" class="<?php echo esc_attr( $class ); ?>"> |
| 38 | 38 | <?php |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | self::getInstance()->set_entry( $entry ); |
| 241 | 241 | |
| 242 | - $base = GravityView_API::directory_link( $post_id ? : $view_id, true ); |
|
| 242 | + $base = GravityView_API::directory_link( $post_id ? : $view_id, true ); |
|
| 243 | 243 | |
| 244 | 244 | if ( empty( $base ) ) { |
| 245 | 245 | gravityview()->log->error( 'Post ID does not exist: {post_id}', array( 'post_id' => $post_id ) ); |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | 'action' => 'delete', |
| 254 | 254 | 'entry_id' => $entry_slug, |
| 255 | 255 | 'gvid' => $view_id, |
| 256 | - 'view_id' => $view_id, |
|
| 256 | + 'view_id' => $view_id, |
|
| 257 | 257 | ), $base ); |
| 258 | 258 | |
| 259 | 259 | $url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' ); |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | * @since 1.16.4 |
| 428 | 428 | * @param int $entry_id ID of the Gravity Forms entry |
| 429 | 429 | * @param array $entry Deleted entry array |
| 430 | - */ |
|
| 430 | + */ |
|
| 431 | 431 | do_action( 'gravityview/delete-entry/deleted', $entry_id, $entry ); |
| 432 | 432 | } |
| 433 | 433 | |
@@ -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,104 +22,104 @@ 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 | add_action( 'wp', array( $this, 'add_hooks' ), 10 ); |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Add hooks to trigger updating the user |
| 45 | 45 | * |
| 46 | 46 | * @since 1.18 |
| 47 | 47 | */ |
| 48 | - public function add_hooks() { |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
| 52 | - * @since 1.11 |
|
| 53 | - * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
| 54 | - */ |
|
| 55 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 56 | - |
|
| 57 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
| 58 | - |
|
| 59 | - // last resort in case the current user display name don't match any of the defaults |
|
| 60 | - add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Update the WordPress user profile based on the GF User Registration create feed |
|
| 66 | - * |
|
| 67 | - * @since 1.11 |
|
| 68 | - * |
|
| 69 | - * @param array $form Gravity Forms form array |
|
| 70 | - * @param string $entry_id Gravity Forms entry ID |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public function update_user( $form = array(), $entry_id = 0 ) { |
|
| 74 | - |
|
| 75 | - if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 76 | - gravityview()->log->error( 'GFAPI or User Registration class not found; not updating the user' ); |
|
| 77 | - return; |
|
| 78 | - } elseif( empty( $entry_id ) ) { |
|
| 79 | - gravityview()->log->error( 'Entry ID is empty [{entry_id}]; not updating the user', array( 'entry_id' => $entry_id ) ); |
|
| 80 | - return; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** @var GF_User_Registration $gf_user_registration */ |
|
| 84 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 85 | - |
|
| 86 | - $entry = GFAPI::get_entry( $entry_id ); |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 90 | - * @since 1.11 |
|
| 91 | - * @param array $entry Gravity Forms entry |
|
| 92 | - * @param array $form Gravity Forms form |
|
| 93 | - */ |
|
| 94 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 95 | - |
|
| 96 | - $config = $this->get_feed_configuration( $entry, $form ); |
|
| 97 | - |
|
| 98 | - // Make sure the feed is active |
|
| 99 | - if ( ! \GV\Utils::get( $config, 'is_active', false ) ) { |
|
| 48 | + public function add_hooks() { |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
| 52 | + * @since 1.11 |
|
| 53 | + * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
| 54 | + */ |
|
| 55 | + if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 56 | + |
|
| 57 | + add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
| 58 | + |
|
| 59 | + // last resort in case the current user display name don't match any of the defaults |
|
| 60 | + add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Update the WordPress user profile based on the GF User Registration create feed |
|
| 66 | + * |
|
| 67 | + * @since 1.11 |
|
| 68 | + * |
|
| 69 | + * @param array $form Gravity Forms form array |
|
| 70 | + * @param string $entry_id Gravity Forms entry ID |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public function update_user( $form = array(), $entry_id = 0 ) { |
|
| 74 | + |
|
| 75 | + if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 76 | + gravityview()->log->error( 'GFAPI or User Registration class not found; not updating the user' ); |
|
| 100 | 77 | return; |
| 101 | - } |
|
| 78 | + } elseif( empty( $entry_id ) ) { |
|
| 79 | + gravityview()->log->error( 'Entry ID is empty [{entry_id}]; not updating the user', array( 'entry_id' => $entry_id ) ); |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** @var GF_User_Registration $gf_user_registration */ |
|
| 84 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 85 | + |
|
| 86 | + $entry = GFAPI::get_entry( $entry_id ); |
|
| 102 | 87 | |
| 103 | - // If an Update feed, make sure the conditions are met. |
|
| 104 | - if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
|
| 105 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - } |
|
| 88 | + /** |
|
| 89 | + * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 90 | + * @since 1.11 |
|
| 91 | + * @param array $entry Gravity Forms entry |
|
| 92 | + * @param array $form Gravity Forms form |
|
| 93 | + */ |
|
| 94 | + $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 95 | + |
|
| 96 | + $config = $this->get_feed_configuration( $entry, $form ); |
|
| 97 | + |
|
| 98 | + // Make sure the feed is active |
|
| 99 | + if ( ! \GV\Utils::get( $config, 'is_active', false ) ) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 109 | 102 | |
| 110 | - // The priority is set to 3 so that default priority (10) will still override it |
|
| 111 | - add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 112 | - add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 103 | + // If an Update feed, make sure the conditions are met. |
|
| 104 | + if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
|
| 105 | + if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + } |
|
| 113 | 109 | |
| 114 | - // Trigger the User Registration update user method |
|
| 115 | - $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 110 | + // The priority is set to 3 so that default priority (10) will still override it |
|
| 111 | + add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 112 | + add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 116 | 113 | |
| 117 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 118 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 114 | + // Trigger the User Registration update user method |
|
| 115 | + $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 119 | 116 | |
| 120 | - // Prevent double-triggering by removing the hook |
|
| 121 | - remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 122 | - } |
|
| 117 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 118 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 119 | + |
|
| 120 | + // Prevent double-triggering by removing the hook |
|
| 121 | + remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Get the User Registration feed configuration for the entry & form |
@@ -134,185 +134,185 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @return array |
| 136 | 136 | */ |
| 137 | - public function get_feed_configuration( $entry, $form ) { |
|
| 138 | - |
|
| 139 | - /** @var GF_User_Registration $gf_user_registration */ |
|
| 140 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 141 | - |
|
| 142 | - $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 146 | - * @since 1.15 |
|
| 147 | - * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 148 | - * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 149 | - * @param[in] array $form Gravity Forms form array |
|
| 150 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 151 | - */ |
|
| 152 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 153 | - |
|
| 154 | - if( $preserve_role ) { |
|
| 155 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Make sure the current display name is not changed with the update user method. |
|
| 162 | - * @since 1.15 |
|
| 163 | - */ |
|
| 164 | - $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 168 | - * @since 1.14 |
|
| 169 | - * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 170 | - * @param[in] array $form Gravity Forms form array |
|
| 171 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 172 | - */ |
|
| 173 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 174 | - |
|
| 175 | - return $config; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Calculate the user display name format |
|
| 180 | - * |
|
| 181 | - * @since 1.15 |
|
| 182 | - * @since 1.20 Returns false if user not found at $user_id |
|
| 183 | - * |
|
| 184 | - * @param int $user_id WP User ID |
|
| 185 | - * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 186 | - */ |
|
| 187 | - public function match_current_display_name( $user_id ) { |
|
| 188 | - |
|
| 189 | - $user = get_userdata( $user_id ); |
|
| 190 | - |
|
| 191 | - if( ! $user ) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $names = $this->generate_display_names( $user ); |
|
| 196 | - |
|
| 197 | - $format = array_search( $user->display_name, $names, true ); |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 201 | - * @see restore_display_name |
|
| 202 | - */ |
|
| 203 | - if( false === $format ) { |
|
| 204 | - $this->_user_before_update = $user; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $format; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Generate an array of all the user display names possibilities |
|
| 212 | - * |
|
| 213 | - * @since 1.15 |
|
| 214 | - * |
|
| 215 | - * @param object $profileuser WP_User object |
|
| 216 | - * @return array List all the possible display names for a certain User object |
|
| 217 | - */ |
|
| 218 | - public function generate_display_names( $profileuser ) { |
|
| 219 | - |
|
| 220 | - $public_display = array(); |
|
| 221 | - $public_display['nickname'] = $profileuser->nickname; |
|
| 222 | - $public_display['username'] = $profileuser->user_login; |
|
| 223 | - |
|
| 224 | - if ( !empty($profileuser->first_name) ) { |
|
| 225 | - $public_display['firstname'] = $profileuser->first_name; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - if ( !empty($profileuser->last_name) ) { |
|
| 229 | - $public_display['lastname'] = $profileuser->last_name; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 233 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 234 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - $public_display = array_map( 'trim', $public_display ); |
|
| 238 | - $public_display = array_unique( $public_display ); |
|
| 239 | - |
|
| 240 | - return $public_display; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 246 | - * |
|
| 247 | - * @see GFUser::update_user() |
|
| 248 | - * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 249 | - * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 250 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 251 | - * @param string $password User password |
|
| 252 | - * @return int|false|WP_Error|null True: User updated; False: $user_id not a valid User ID; WP_Error: User update error; Null: Method didn't process |
|
| 253 | - */ |
|
| 254 | - public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 258 | - * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 259 | - * @since 1.14.4 |
|
| 260 | - * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 261 | - */ |
|
| 262 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 263 | - |
|
| 264 | - $is_update_feed = ( $config && \GV\Utils::get( $config, 'meta/feed_type' ) === 'update' ); |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Don't restore display name: |
|
| 268 | - * - either disabled, |
|
| 269 | - * - or it is an Update feed (we only care about Create feed) |
|
| 270 | - * - or we don't need as we found the correct format before updating user. |
|
| 271 | - * @since 1.14.4 |
|
| 272 | - */ |
|
| 273 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 274 | - return null; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $user_after_update = get_userdata( $user_id ); |
|
| 278 | - |
|
| 279 | - // User not found |
|
| 280 | - if ( ! $user_after_update ) { |
|
| 281 | - gravityview()->log->error( 'User not found at $user_id #{user_id}', array( 'user_id' => $user_id ) ); |
|
| 282 | - return false; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $restored_user = $user_after_update; |
|
| 286 | - |
|
| 287 | - // Restore previous display_name |
|
| 288 | - $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 289 | - |
|
| 290 | - // Don't have WP update the password. |
|
| 291 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 295 | - * @since 1.14 |
|
| 296 | - * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 297 | - * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 298 | - * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 299 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 300 | - */ |
|
| 301 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 302 | - |
|
| 303 | - $updated = wp_update_user( $restored_user ); |
|
| 304 | - |
|
| 305 | - if( is_wp_error( $updated ) ) { |
|
| 306 | - gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
|
| 307 | - } else { |
|
| 308 | - gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - $this->_user_before_update = null; |
|
| 312 | - |
|
| 313 | - unset( $restored_user, $user_after_update ); |
|
| 314 | - |
|
| 315 | - return $updated; |
|
| 316 | - } |
|
| 137 | + public function get_feed_configuration( $entry, $form ) { |
|
| 138 | + |
|
| 139 | + /** @var GF_User_Registration $gf_user_registration */ |
|
| 140 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 141 | + |
|
| 142 | + $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 146 | + * @since 1.15 |
|
| 147 | + * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 148 | + * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 149 | + * @param[in] array $form Gravity Forms form array |
|
| 150 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 151 | + */ |
|
| 152 | + $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 153 | + |
|
| 154 | + if( $preserve_role ) { |
|
| 155 | + $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Make sure the current display name is not changed with the update user method. |
|
| 162 | + * @since 1.15 |
|
| 163 | + */ |
|
| 164 | + $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 168 | + * @since 1.14 |
|
| 169 | + * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 170 | + * @param[in] array $form Gravity Forms form array |
|
| 171 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 172 | + */ |
|
| 173 | + $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 174 | + |
|
| 175 | + return $config; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Calculate the user display name format |
|
| 180 | + * |
|
| 181 | + * @since 1.15 |
|
| 182 | + * @since 1.20 Returns false if user not found at $user_id |
|
| 183 | + * |
|
| 184 | + * @param int $user_id WP User ID |
|
| 185 | + * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 186 | + */ |
|
| 187 | + public function match_current_display_name( $user_id ) { |
|
| 188 | + |
|
| 189 | + $user = get_userdata( $user_id ); |
|
| 190 | + |
|
| 191 | + if( ! $user ) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $names = $this->generate_display_names( $user ); |
|
| 196 | + |
|
| 197 | + $format = array_search( $user->display_name, $names, true ); |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 201 | + * @see restore_display_name |
|
| 202 | + */ |
|
| 203 | + if( false === $format ) { |
|
| 204 | + $this->_user_before_update = $user; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $format; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Generate an array of all the user display names possibilities |
|
| 212 | + * |
|
| 213 | + * @since 1.15 |
|
| 214 | + * |
|
| 215 | + * @param object $profileuser WP_User object |
|
| 216 | + * @return array List all the possible display names for a certain User object |
|
| 217 | + */ |
|
| 218 | + public function generate_display_names( $profileuser ) { |
|
| 219 | + |
|
| 220 | + $public_display = array(); |
|
| 221 | + $public_display['nickname'] = $profileuser->nickname; |
|
| 222 | + $public_display['username'] = $profileuser->user_login; |
|
| 223 | + |
|
| 224 | + if ( !empty($profileuser->first_name) ) { |
|
| 225 | + $public_display['firstname'] = $profileuser->first_name; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + if ( !empty($profileuser->last_name) ) { |
|
| 229 | + $public_display['lastname'] = $profileuser->last_name; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 233 | + $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 234 | + $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + $public_display = array_map( 'trim', $public_display ); |
|
| 238 | + $public_display = array_unique( $public_display ); |
|
| 239 | + |
|
| 240 | + return $public_display; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 246 | + * |
|
| 247 | + * @see GFUser::update_user() |
|
| 248 | + * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 249 | + * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 250 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 251 | + * @param string $password User password |
|
| 252 | + * @return int|false|WP_Error|null True: User updated; False: $user_id not a valid User ID; WP_Error: User update error; Null: Method didn't process |
|
| 253 | + */ |
|
| 254 | + public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 258 | + * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 259 | + * @since 1.14.4 |
|
| 260 | + * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 261 | + */ |
|
| 262 | + $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 263 | + |
|
| 264 | + $is_update_feed = ( $config && \GV\Utils::get( $config, 'meta/feed_type' ) === 'update' ); |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Don't restore display name: |
|
| 268 | + * - either disabled, |
|
| 269 | + * - or it is an Update feed (we only care about Create feed) |
|
| 270 | + * - or we don't need as we found the correct format before updating user. |
|
| 271 | + * @since 1.14.4 |
|
| 272 | + */ |
|
| 273 | + if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 274 | + return null; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $user_after_update = get_userdata( $user_id ); |
|
| 278 | + |
|
| 279 | + // User not found |
|
| 280 | + if ( ! $user_after_update ) { |
|
| 281 | + gravityview()->log->error( 'User not found at $user_id #{user_id}', array( 'user_id' => $user_id ) ); |
|
| 282 | + return false; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $restored_user = $user_after_update; |
|
| 286 | + |
|
| 287 | + // Restore previous display_name |
|
| 288 | + $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 289 | + |
|
| 290 | + // Don't have WP update the password. |
|
| 291 | + unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 295 | + * @since 1.14 |
|
| 296 | + * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 297 | + * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 298 | + * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 299 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 300 | + */ |
|
| 301 | + $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 302 | + |
|
| 303 | + $updated = wp_update_user( $restored_user ); |
|
| 304 | + |
|
| 305 | + if( is_wp_error( $updated ) ) { |
|
| 306 | + gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
|
| 307 | + } else { |
|
| 308 | + gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + $this->_user_before_update = null; |
|
| 312 | + |
|
| 313 | + unset( $restored_user, $user_after_update ); |
|
| 314 | + |
|
| 315 | + return $updated; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | 318 | } //end class |
@@ -52,14 +52,14 @@ discard block |
||
| 52 | 52 | // matching regex => the value is the method to call to replace the value. |
| 53 | 53 | $gv_modifiers = array( |
| 54 | 54 | 'maxwords:(\d+)' => 'modifier_maxwords', /** @see modifier_maxwords */ |
| 55 | - 'timestamp' => 'modifier_timestamp', /** @see modifier_timestamp */ |
|
| 55 | + 'timestamp' => 'modifier_timestamp', /** @see modifier_timestamp */ |
|
| 56 | 56 | 'explode' => 'modifier_explode', /** @see modifier_explode */ |
| 57 | 57 | |
| 58 | 58 | /** @see modifier_strings */ |
| 59 | 59 | 'urlencode' => 'modifier_strings', |
| 60 | 60 | 'wpautop' => 'modifier_strings', |
| 61 | - 'esc_html' => 'modifier_strings', |
|
| 62 | - 'sanitize_html_class' => 'modifier_strings', |
|
| 61 | + 'esc_html' => 'modifier_strings', |
|
| 62 | + 'sanitize_html_class' => 'modifier_strings', |
|
| 63 | 63 | 'sanitize_title' => 'modifier_strings', |
| 64 | 64 | 'strtolower' => 'modifier_strings', |
| 65 | 65 | 'strtoupper' => 'modifier_strings', |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | $atts = array( |
| 459 | 459 | 'format' => self::get_format_from_modifiers( $exploded, false ), |
| 460 | - 'human' => in_array( 'human', $exploded ), // {date_created:human} |
|
| 460 | + 'human' => in_array( 'human', $exploded ), // {date_created:human} |
|
| 461 | 461 | 'diff' => in_array( 'diff', $exploded ), // {date_created:diff} |
| 462 | 462 | 'raw' => in_array( 'raw', $exploded ), // {date_created:raw} |
| 463 | 463 | 'timestamp' => in_array( 'timestamp', $exploded ), // {date_created:timestamp} |
@@ -109,7 +109,7 @@ |
||
| 109 | 109 | $field_data = array( |
| 110 | 110 | 'label' => \GV\Utils::get( $edit_field, 'custom_label' ), |
| 111 | 111 | 'customLabel' => \GV\Utils::get( $edit_field, 'custom_label' ), |
| 112 | - 'content' => \GV\Utils::get( $edit_field, 'content' ), |
|
| 112 | + 'content' => \GV\Utils::get( $edit_field, 'content' ), |
|
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | 115 | // Replace merge tags in the content |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | private function add_hooks() { |
| 38 | - /** @see \GV\Field::get_value_filters */ |
|
| 38 | + /** @see \GV\Field::get_value_filters */ |
|
| 39 | 39 | add_filter( "gravityview/field/{$this->name}/output", array( $this, 'get_content' ), 4, 2 ); |
| 40 | 40 | add_action( 'gravityview/template/after', array( $this, 'print_script'), 10, 1 ); |
| 41 | 41 | add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | public function get_content( $output, $template ) { |
| 77 | 77 | $entry = $template->entry; |
| 78 | 78 | |
| 79 | - $star_url = GFCommon::get_base_url() .'/images/star' . intval( $entry['is_starred'] ) .'.png'; |
|
| 79 | + $star_url = GFCommon::get_base_url() .'/images/star' . intval( $entry['is_starred'] ) .'.png'; |
|
| 80 | 80 | |
| 81 | 81 | $entry_id = ''; |
| 82 | 82 | |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * Add JS to the bottom of the View if there is a star field and user has `gravityview_edit_entries` cap |
| 97 | - * |
|
| 97 | + * |
|
| 98 | 98 | * @param \GV\Template_Context $context The template context |
| 99 | - * @since 2.0 |
|
| 100 | - * |
|
| 101 | - * @return void |
|
| 99 | + * @since 2.0 |
|
| 100 | + * |
|
| 101 | + * @return void |
|
| 102 | 102 | */ |
| 103 | 103 | public function print_script( $context ) { |
| 104 | 104 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | if ( ! GravityView_Roles_Capabilities::has_cap( 'gravityview_edit_entries' ) ) { |
| 110 | - return; |
|
| 110 | + return; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | ?> |