@@ -10,160 +10,160 @@ discard block |
||
| 10 | 10 | * |
| 11 | 11 | * @var string |
| 12 | 12 | */ |
| 13 | - protected $name; |
|
| 13 | + protected $name; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Field settings |
| 17 | 17 | * |
| 18 | 18 | * @var array |
| 19 | 19 | */ |
| 20 | - protected $field; |
|
| 20 | + protected $field; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Field current value |
| 24 | 24 | * |
| 25 | 25 | * @var mixed |
| 26 | 26 | */ |
| 27 | - protected $value; |
|
| 28 | - |
|
| 29 | - function __construct( $name = '', $field = array(), $curr_value = NULL ) { |
|
| 30 | - |
|
| 31 | - $this->name = $name; |
|
| 32 | - |
|
| 33 | - $defaults = self::get_field_defaults(); |
|
| 34 | - |
|
| 35 | - // Backward compatibility |
|
| 36 | - if( !empty( $field['choices'] ) ) { |
|
| 37 | - $field['options'] = $field['choices']; |
|
| 38 | - unset( $field['choices'] ); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - $this->field = wp_parse_args( $field, $defaults ); |
|
| 42 | - |
|
| 43 | - $this->value = is_null( $curr_value ) ? $this->field['value'] : $curr_value; |
|
| 44 | - |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Returns the default details for a field option |
|
| 49 | - * |
|
| 50 | - * - default // default option value, in case nothing is defined (@deprecated) |
|
| 51 | - * - desc // option description |
|
| 52 | - * - value // the option default value |
|
| 53 | - * - label // the option label |
|
| 54 | - * - left_label // In case of checkboxes, left label will appear on the left of the checkbox |
|
| 55 | - * - id // the field id |
|
| 56 | - * - type // the option type ( text, checkbox, select, ... ) |
|
| 57 | - * - options // when type is select, define the select options ('choices' is @deprecated) |
|
| 58 | - * - merge_tags // if the option supports merge tags feature |
|
| 59 | - * - class // (new) define extra classes for the field |
|
| 60 | - * - tooltip // |
|
| 61 | - * |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 64 | - public static function get_field_defaults() { |
|
| 65 | - return array( |
|
| 66 | - 'desc' => '', |
|
| 67 | - 'value' => NULL, |
|
| 68 | - 'label' => '', |
|
| 69 | - 'left_label' => NULL, |
|
| 70 | - 'id' => NULL, |
|
| 71 | - 'type' => 'text', |
|
| 72 | - 'options' => NULL, |
|
| 73 | - 'merge_tags' => true, |
|
| 74 | - 'class' => '', |
|
| 75 | - 'tooltip' => NULL, |
|
| 76 | - 'requires' => NULL |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - function get_tooltip() { |
|
| 82 | - if( !function_exists('gform_tooltip') ) { |
|
| 83 | - return NULL; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return !empty( $this->field['tooltip'] ) ? ' '.gform_tooltip( $this->field['tooltip'] , false, true ) : NULL; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Build input id based on the name |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - function get_field_id() { |
|
| 94 | - if( isset( $this->field['id'] ) ) { |
|
| 95 | - return esc_attr( $this->field['id'] ); |
|
| 96 | - } |
|
| 97 | - return esc_attr( sanitize_html_class( $this->name ) ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Retrieve field label |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - function get_field_label() { |
|
| 105 | - return esc_html( trim( $this->field['label'] ) ); |
|
| 106 | - } |
|
| 27 | + protected $value; |
|
| 28 | + |
|
| 29 | + function __construct( $name = '', $field = array(), $curr_value = NULL ) { |
|
| 30 | + |
|
| 31 | + $this->name = $name; |
|
| 32 | + |
|
| 33 | + $defaults = self::get_field_defaults(); |
|
| 34 | + |
|
| 35 | + // Backward compatibility |
|
| 36 | + if( !empty( $field['choices'] ) ) { |
|
| 37 | + $field['options'] = $field['choices']; |
|
| 38 | + unset( $field['choices'] ); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + $this->field = wp_parse_args( $field, $defaults ); |
|
| 42 | + |
|
| 43 | + $this->value = is_null( $curr_value ) ? $this->field['value'] : $curr_value; |
|
| 44 | + |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Returns the default details for a field option |
|
| 49 | + * |
|
| 50 | + * - default // default option value, in case nothing is defined (@deprecated) |
|
| 51 | + * - desc // option description |
|
| 52 | + * - value // the option default value |
|
| 53 | + * - label // the option label |
|
| 54 | + * - left_label // In case of checkboxes, left label will appear on the left of the checkbox |
|
| 55 | + * - id // the field id |
|
| 56 | + * - type // the option type ( text, checkbox, select, ... ) |
|
| 57 | + * - options // when type is select, define the select options ('choices' is @deprecated) |
|
| 58 | + * - merge_tags // if the option supports merge tags feature |
|
| 59 | + * - class // (new) define extra classes for the field |
|
| 60 | + * - tooltip // |
|
| 61 | + * |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | + public static function get_field_defaults() { |
|
| 65 | + return array( |
|
| 66 | + 'desc' => '', |
|
| 67 | + 'value' => NULL, |
|
| 68 | + 'label' => '', |
|
| 69 | + 'left_label' => NULL, |
|
| 70 | + 'id' => NULL, |
|
| 71 | + 'type' => 'text', |
|
| 72 | + 'options' => NULL, |
|
| 73 | + 'merge_tags' => true, |
|
| 74 | + 'class' => '', |
|
| 75 | + 'tooltip' => NULL, |
|
| 76 | + 'requires' => NULL |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + function get_tooltip() { |
|
| 82 | + if( !function_exists('gform_tooltip') ) { |
|
| 83 | + return NULL; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return !empty( $this->field['tooltip'] ) ? ' '.gform_tooltip( $this->field['tooltip'] , false, true ) : NULL; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Build input id based on the name |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + function get_field_id() { |
|
| 94 | + if( isset( $this->field['id'] ) ) { |
|
| 95 | + return esc_attr( $this->field['id'] ); |
|
| 96 | + } |
|
| 97 | + return esc_attr( sanitize_html_class( $this->name ) ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Retrieve field label |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + function get_field_label() { |
|
| 105 | + return esc_html( trim( $this->field['label'] ) ); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * Retrieve field left label |
| 110 | - * |
|
| 111 | - * @since 1.7 |
|
| 112 | - * |
|
| 110 | + * |
|
| 111 | + * @since 1.7 |
|
| 112 | + * |
|
| 113 | 113 | * @return string |
| 114 | 114 | */ |
| 115 | 115 | function get_field_left_label() { |
| 116 | 116 | return ! empty( $this->field['left_label'] ) ? esc_html( trim( $this->field['left_label'] ) ) : NULL; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Retrieve field label class |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - function get_label_class() { |
|
| 124 | - return 'gv-label-'. sanitize_html_class( $this->field['type'] ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Retrieve field description |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - function get_field_desc() { |
|
| 133 | - return !empty( $this->field['desc'] ) ? '<span class="howto">'. $this->field['desc'] .'</span>' : ''; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Verify if field should have merge tags |
|
| 139 | - * @return boolean |
|
| 140 | - */ |
|
| 141 | - function show_merge_tags() { |
|
| 142 | - // Show the merge tags if the field is a list view |
|
| 143 | - $is_list = preg_match( '/_list-/ism', $this->name ); |
|
| 144 | - // Or is a single entry view |
|
| 145 | - $is_single = preg_match( '/single_/ism', $this->name ); |
|
| 146 | - |
|
| 147 | - return ( $is_single || $is_list ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * important! Override this class |
|
| 154 | - * outputs the field option html |
|
| 155 | - */ |
|
| 156 | - function render_option() { |
|
| 157 | - // to replace on each field |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * important! Override this class if needed |
|
| 162 | - * outputs the field setting html |
|
| 163 | - */ |
|
| 164 | - function render_setting( $override_input = NULL ) { |
|
| 165 | - |
|
| 166 | - if( !empty( $this->field['full_width'] ) ) { ?> |
|
| 119 | + /** |
|
| 120 | + * Retrieve field label class |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + function get_label_class() { |
|
| 124 | + return 'gv-label-'. sanitize_html_class( $this->field['type'] ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Retrieve field description |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + function get_field_desc() { |
|
| 133 | + return !empty( $this->field['desc'] ) ? '<span class="howto">'. $this->field['desc'] .'</span>' : ''; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Verify if field should have merge tags |
|
| 139 | + * @return boolean |
|
| 140 | + */ |
|
| 141 | + function show_merge_tags() { |
|
| 142 | + // Show the merge tags if the field is a list view |
|
| 143 | + $is_list = preg_match( '/_list-/ism', $this->name ); |
|
| 144 | + // Or is a single entry view |
|
| 145 | + $is_single = preg_match( '/single_/ism', $this->name ); |
|
| 146 | + |
|
| 147 | + return ( $is_single || $is_list ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * important! Override this class |
|
| 154 | + * outputs the field option html |
|
| 155 | + */ |
|
| 156 | + function render_option() { |
|
| 157 | + // to replace on each field |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * important! Override this class if needed |
|
| 162 | + * outputs the field setting html |
|
| 163 | + */ |
|
| 164 | + function render_setting( $override_input = NULL ) { |
|
| 165 | + |
|
| 166 | + if( !empty( $this->field['full_width'] ) ) { ?> |
|
| 167 | 167 | <th scope="row" colspan="2"> |
| 168 | 168 | <div> |
| 169 | 169 | <label for="<?php echo $this->get_field_id(); ?>"> |
@@ -183,14 +183,14 @@ discard block |
||
| 183 | 183 | </td> |
| 184 | 184 | <?php } |
| 185 | 185 | |
| 186 | - } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * important! Override this class |
|
| 190 | - * outputs the input html part |
|
| 191 | - */ |
|
| 192 | - function render_input( $override_input ) { |
|
| 193 | - echo ''; |
|
| 194 | - } |
|
| 188 | + /** |
|
| 189 | + * important! Override this class |
|
| 190 | + * outputs the input html part |
|
| 191 | + */ |
|
| 192 | + function render_input( $override_input ) { |
|
| 193 | + echo ''; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | 196 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @return void |
| 97 | 97 | */ |
| 98 | 98 | public static function connected_form_warning( $form_id = 0 ) { |
| 99 | - global $pagenow; |
|
| 99 | + global $pagenow; |
|
| 100 | 100 | |
| 101 | 101 | if ( ! is_int( $form_id ) || $pagenow === 'post-new.php' ) { |
| 102 | 102 | return; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | 7 => sprintf(__( 'View saved. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text, |
| 243 | 243 | 8 => __( 'View submitted.', 'gravityview' ), |
| 244 | 244 | 9 => sprintf( |
| 245 | - /* translators: Date and time the View is scheduled to be published */ |
|
| 245 | + /* translators: Date and time the View is scheduled to be published */ |
|
| 246 | 246 | __( 'View scheduled for: %1$s.', 'gravityview' ), |
| 247 | 247 | // translators: Publish box date format, see http://php.net/date |
| 248 | 248 | date_i18n( __( 'M j, Y @ G:i', 'gravityview' ), strtotime( ( isset( $post->post_date ) ? $post->post_date : NULL ) ) ) |
@@ -299,7 +299,6 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @deprecated since 1.12 |
| 301 | 301 | * @see GravityView_Compatibility::get_plugin_status() |
| 302 | - |
|
| 303 | 302 | * @return boolean|string True: plugin is active; False: plugin file doesn't exist at path; 'inactive' it's inactive |
| 304 | 303 | */ |
| 305 | 304 | static function get_plugin_status( $location = '' ) { |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | $field_data = array( |
| 103 | 103 | 'label' => rgar( $edit_field, 'custom_label' ), |
| 104 | 104 | 'customLabel' => rgar( $edit_field, 'custom_label' ), |
| 105 | - 'content' => rgar( $edit_field, 'content' ), |
|
| 105 | + 'content' => rgar( $edit_field, 'content' ), |
|
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | 108 | // Replace merge tags in the content |
@@ -329,34 +329,34 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
| 332 | - * Get the fields for a specific context |
|
| 333 | - * |
|
| 334 | - * @since 1.19.2 |
|
| 335 | - * |
|
| 332 | + * Get the fields for a specific context |
|
| 333 | + * |
|
| 334 | + * @since 1.19.2 |
|
| 335 | + * |
|
| 336 | 336 | * @param string $context [Optional] "directory", "single", or "edit" |
| 337 | 337 | * |
| 338 | 338 | * @return array Array of GravityView field layout configurations |
| 339 | 339 | */ |
| 340 | 340 | public function getContextFields( $context = '' ) { |
| 341 | 341 | |
| 342 | - if( '' === $context ) { |
|
| 343 | - $context = $this->getContext(); |
|
| 344 | - } |
|
| 342 | + if( '' === $context ) { |
|
| 343 | + $context = $this->getContext(); |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | 346 | $fields = $this->getFields(); |
| 347 | 347 | |
| 348 | - foreach ( (array) $fields as $key => $context_fields ) { |
|
| 348 | + foreach ( (array) $fields as $key => $context_fields ) { |
|
| 349 | 349 | |
| 350 | - // Formatted as `{context}_{template id}-{zone name}`, so we want just the $context to match against |
|
| 351 | - $matches = explode( '_', $key ); |
|
| 350 | + // Formatted as `{context}_{template id}-{zone name}`, so we want just the $context to match against |
|
| 351 | + $matches = explode( '_', $key ); |
|
| 352 | 352 | |
| 353 | - if( isset( $matches[0] ) && $matches[0] === $context ) { |
|
| 354 | - return $context_fields; |
|
| 355 | - } |
|
| 356 | - } |
|
| 353 | + if( isset( $matches[0] ) && $matches[0] === $context ) { |
|
| 354 | + return $context_fields; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | 358 | return array(); |
| 359 | - } |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | 362 | * @param array $fields |
@@ -449,10 +449,10 @@ discard block |
||
| 449 | 449 | */ |
| 450 | 450 | public function getPaging() { |
| 451 | 451 | |
| 452 | - $default_params = array( |
|
| 453 | - 'offset' => 0, |
|
| 454 | - 'page_size' => 20, |
|
| 455 | - ); |
|
| 452 | + $default_params = array( |
|
| 453 | + 'offset' => 0, |
|
| 454 | + 'page_size' => 20, |
|
| 455 | + ); |
|
| 456 | 456 | |
| 457 | 457 | return wp_parse_args( $this->paging, $default_params ); |
| 458 | 458 | } |
@@ -509,10 +509,10 @@ discard block |
||
| 509 | 509 | public function getSorting() { |
| 510 | 510 | |
| 511 | 511 | $defaults_params = array( |
| 512 | - 'sort_field' => 'date_created', |
|
| 513 | - 'sort_direction' => 'ASC', |
|
| 514 | - 'is_numeric' => false, |
|
| 515 | - ); |
|
| 512 | + 'sort_field' => 'date_created', |
|
| 513 | + 'sort_direction' => 'ASC', |
|
| 514 | + 'is_numeric' => false, |
|
| 515 | + ); |
|
| 516 | 516 | |
| 517 | 517 | return wp_parse_args( $this->sorting, $defaults_params ); |
| 518 | 518 | } |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | // Call the custom API. |
| 116 | 116 | $response = wp_remote_post( self::url, array( |
| 117 | 117 | 'timeout' => 15, |
| 118 | - 'sslverify' => false, |
|
| 119 | - 'body' => array( |
|
| 120 | - 'edd_action' => 'check_license', |
|
| 121 | - 'license' => trim( $this->Addon->get_app_setting( 'license_key' ) ), |
|
| 122 | - 'item_name' => self::name, |
|
| 123 | - 'url' => home_url(), |
|
| 124 | - 'site_data' => $this->get_site_data(), |
|
| 125 | - ), |
|
| 118 | + 'sslverify' => false, |
|
| 119 | + 'body' => array( |
|
| 120 | + 'edd_action' => 'check_license', |
|
| 121 | + 'license' => trim( $this->Addon->get_app_setting( 'license_key' ) ), |
|
| 122 | + 'item_name' => self::name, |
|
| 123 | + 'url' => home_url(), |
|
| 124 | + 'site_data' => $this->get_site_data(), |
|
| 125 | + ), |
|
| 126 | 126 | )); |
| 127 | 127 | |
| 128 | 128 | // make sure the response came back okay |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | // Update option with passed data license |
| 676 | 676 | $settings = $this->Addon->get_app_settings(); |
| 677 | 677 | |
| 678 | - $settings['license_key'] = $license_data->license_key = trim( $data['license'] ); |
|
| 678 | + $settings['license_key'] = $license_data->license_key = trim( $data['license'] ); |
|
| 679 | 679 | $settings['license_key_status'] = $license_data->license; |
| 680 | 680 | $settings['license_key_response'] = (array)$license_data; |
| 681 | 681 | |
@@ -40,7 +40,6 @@ |
||
| 40 | 40 | * Get the default date format for a field based on the field ID and the time format setting |
| 41 | 41 | * |
| 42 | 42 | * @since 1.16.4 |
| 43 | - |
|
| 44 | 43 | * @param string $date_format The Gravity Forms date format for the field. Default: "mdy" |
| 45 | 44 | * @param int $field_id The ID of the field. Used to figure out full date/day/month/year |
| 46 | 45 | * |
@@ -306,12 +306,12 @@ discard block |
||
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
| 309 | - * @hack |
|
| 310 | - * In case of email/email confirmation, the input for email has the same id as the parent field |
|
| 311 | - */ |
|
| 309 | + * @hack |
|
| 310 | + * In case of email/email confirmation, the input for email has the same id as the parent field |
|
| 311 | + */ |
|
| 312 | 312 | if( 'email' === $field['type'] && false === strpos( $input['id'], '.' ) ) { |
| 313 | - continue; |
|
| 314 | - } |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | 315 | $fields["{$input['id']}"] = array( |
| 316 | 316 | 'label' => rgar( $input, 'label' ), |
| 317 | 317 | 'customLabel' => rgar( $input, 'customLabel' ), |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | } elseif ( 'delete' === GFForms::get( 'action' ) ) { |
| 489 | 489 | $criteria['context_view_id'] = isset( $_GET['view_id'] ) ? intval( $_GET['view_id'] ) : null; |
| 490 | 490 | } elseif( !isset( $criteria['context_view_id'] ) ) { |
| 491 | - // Prevent overriding the Context View ID: Some widgets could set the context_view_id (e.g. Recent Entries widget) |
|
| 491 | + // Prevent overriding the Context View ID: Some widgets could set the context_view_id (e.g. Recent Entries widget) |
|
| 492 | 492 | $criteria['context_view_id'] = null; |
| 493 | 493 | } |
| 494 | 494 | |
@@ -1251,7 +1251,7 @@ discard block |
||
| 1251 | 1251 | ), |
| 1252 | 1252 | ); |
| 1253 | 1253 | |
| 1254 | - $fields = $date_created + $fields; |
|
| 1254 | + $fields = $date_created + $fields; |
|
| 1255 | 1255 | |
| 1256 | 1256 | $blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', $blacklist, NULL ); |
| 1257 | 1257 | |
@@ -1263,13 +1263,13 @@ discard block |
||
| 1263 | 1263 | } |
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | - /** |
|
| 1267 | - * @filter `gravityview/common/sortable_fields` Filter the sortable fields |
|
| 1268 | - * @since 1.12 |
|
| 1269 | - * @param array $fields Sub-set of GF form fields that are sortable |
|
| 1270 | - * @param int $formid The Gravity Forms form ID that the fields are from |
|
| 1271 | - */ |
|
| 1272 | - $fields = apply_filters( 'gravityview/common/sortable_fields', $fields, $formid ); |
|
| 1266 | + /** |
|
| 1267 | + * @filter `gravityview/common/sortable_fields` Filter the sortable fields |
|
| 1268 | + * @since 1.12 |
|
| 1269 | + * @param array $fields Sub-set of GF form fields that are sortable |
|
| 1270 | + * @param int $formid The Gravity Forms form ID that the fields are from |
|
| 1271 | + */ |
|
| 1272 | + $fields = apply_filters( 'gravityview/common/sortable_fields', $fields, $formid ); |
|
| 1273 | 1273 | |
| 1274 | 1274 | return $fields; |
| 1275 | 1275 | } |
@@ -1561,26 +1561,26 @@ discard block |
||
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | |
| 1564 | - /** |
|
| 1565 | - * Display updated/error notice |
|
| 1566 | - * |
|
| 1567 | - * @since 1.19.2 Added $cap and $object_id parameters |
|
| 1568 | - * |
|
| 1569 | - * @param string $notice text/HTML of notice |
|
| 1570 | - * @param string $class CSS class for notice (`updated` or `error`) |
|
| 1571 | - * @param string $cap [Optional] Define a capability required to show a notice. If not set, displays to all caps. |
|
| 1572 | - * |
|
| 1573 | - * @return string |
|
| 1574 | - */ |
|
| 1575 | - public static function generate_notice( $notice, $class = '', $cap = '', $object_id = null ) { |
|
| 1576 | - |
|
| 1577 | - // If $cap is defined, only show notice if user has capability |
|
| 1578 | - if( $cap && ! GVCommon::has_cap( $cap, $object_id ) ) { |
|
| 1579 | - return ''; |
|
| 1580 | - } |
|
| 1581 | - |
|
| 1582 | - return '<div class="gv-notice '.gravityview_sanitize_html_class( $class ) .'">'. $notice .'</div>'; |
|
| 1583 | - } |
|
| 1564 | + /** |
|
| 1565 | + * Display updated/error notice |
|
| 1566 | + * |
|
| 1567 | + * @since 1.19.2 Added $cap and $object_id parameters |
|
| 1568 | + * |
|
| 1569 | + * @param string $notice text/HTML of notice |
|
| 1570 | + * @param string $class CSS class for notice (`updated` or `error`) |
|
| 1571 | + * @param string $cap [Optional] Define a capability required to show a notice. If not set, displays to all caps. |
|
| 1572 | + * |
|
| 1573 | + * @return string |
|
| 1574 | + */ |
|
| 1575 | + public static function generate_notice( $notice, $class = '', $cap = '', $object_id = null ) { |
|
| 1576 | + |
|
| 1577 | + // If $cap is defined, only show notice if user has capability |
|
| 1578 | + if( $cap && ! GVCommon::has_cap( $cap, $object_id ) ) { |
|
| 1579 | + return ''; |
|
| 1580 | + } |
|
| 1581 | + |
|
| 1582 | + return '<div class="gv-notice '.gravityview_sanitize_html_class( $class ) .'">'. $notice .'</div>'; |
|
| 1583 | + } |
|
| 1584 | 1584 | |
| 1585 | 1585 | /** |
| 1586 | 1586 | * Inspired on \GFCommon::encode_shortcodes, reverse the encoding by replacing the ascii characters by the shortcode brackets |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | self::getInstance()->set_entry( $entry ); |
| 236 | 236 | |
| 237 | - $base = GravityView_API::directory_link( $post_id, true ); |
|
| 237 | + $base = GravityView_API::directory_link( $post_id, true ); |
|
| 238 | 238 | |
| 239 | 239 | if( empty( $base ) ) { |
| 240 | 240 | do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: '.$post_id ); |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | // Use the slug instead of the ID for consistent security |
| 245 | 245 | $entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry ); |
| 246 | 246 | |
| 247 | - $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
|
| 247 | + $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
|
| 248 | 248 | |
| 249 | 249 | $actionurl = add_query_arg( array( |
| 250 | 250 | 'action' => 'delete', |
| 251 | 251 | 'entry_id' => $entry_slug, |
| 252 | 252 | 'gvid' => $view_id, |
| 253 | - 'view_id' => $view_id, |
|
| 253 | + 'view_id' => $view_id, |
|
| 254 | 254 | ), $base ); |
| 255 | 255 | |
| 256 | 256 | $url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' ); |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * @since 1.16.4 |
| 425 | 425 | * @param int $entry_id ID of the Gravity Forms entry |
| 426 | 426 | * @param array $entry Deleted entry array |
| 427 | - */ |
|
| 427 | + */ |
|
| 428 | 428 | do_action( 'gravityview/delete-entry/deleted', $entry_id, $entry ); |
| 429 | 429 | } |
| 430 | 430 | |
@@ -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,102 +22,102 @@ 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 | - do_action( 'gravityview_log_error', __METHOD__ . ': GFAPI or User Registration class not found; not updating the user' ); |
|
| 77 | - return; |
|
| 78 | - } elseif( empty( $entry_id ) ) { |
|
| 79 | - do_action( 'gravityview_log_error', __METHOD__ . ': Entry ID is empty; not updating the user', $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 ( ! rgar( $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 | + do_action( 'gravityview_log_error', __METHOD__ . ': GFAPI or User Registration class not found; not updating the user' ); |
|
| 100 | 77 | return; |
| 101 | - } |
|
| 78 | + } elseif( empty( $entry_id ) ) { |
|
| 79 | + do_action( 'gravityview_log_error', __METHOD__ . ': Entry ID is empty; not updating the user', $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( rgars( $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 ( ! rgar( $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( rgars( $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 | - } |
|
| 117 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 118 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * Get the User Registration feed configuration for the entry & form |
@@ -132,185 +132,185 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @return array |
| 134 | 134 | */ |
| 135 | - public function get_feed_configuration( $entry, $form ) { |
|
| 136 | - |
|
| 137 | - /** @var GF_User_Registration $gf_user_registration */ |
|
| 138 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 139 | - |
|
| 140 | - $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 144 | - * @since 1.15 |
|
| 145 | - * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 146 | - * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 147 | - * @param[in] array $form Gravity Forms form array |
|
| 148 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 149 | - */ |
|
| 150 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 151 | - |
|
| 152 | - if( $preserve_role ) { |
|
| 153 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Make sure the current display name is not changed with the update user method. |
|
| 160 | - * @since 1.15 |
|
| 161 | - */ |
|
| 162 | - $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 166 | - * @since 1.14 |
|
| 167 | - * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 168 | - * @param[in] array $form Gravity Forms form array |
|
| 169 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 170 | - */ |
|
| 171 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 172 | - |
|
| 173 | - return $config; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Calculate the user display name format |
|
| 178 | - * |
|
| 179 | - * @since 1.15 |
|
| 180 | - * @since 1.20 Returns false if user not found at $user_id |
|
| 181 | - * |
|
| 182 | - * @param int $user_id WP User ID |
|
| 183 | - * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 184 | - */ |
|
| 185 | - public function match_current_display_name( $user_id ) { |
|
| 186 | - |
|
| 187 | - $user = get_userdata( $user_id ); |
|
| 188 | - |
|
| 189 | - if( ! $user ) { |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $names = $this->generate_display_names( $user ); |
|
| 194 | - |
|
| 195 | - $format = array_search( $user->display_name, $names, true ); |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 199 | - * @see restore_display_name |
|
| 200 | - */ |
|
| 201 | - if( false === $format ) { |
|
| 202 | - $this->_user_before_update = $user; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return $format; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Generate an array of all the user display names possibilities |
|
| 210 | - * |
|
| 211 | - * @since 1.15 |
|
| 212 | - * |
|
| 213 | - * @param object $profileuser WP_User object |
|
| 214 | - * @return array List all the possible display names for a certain User object |
|
| 215 | - */ |
|
| 216 | - public function generate_display_names( $profileuser ) { |
|
| 217 | - |
|
| 218 | - $public_display = array(); |
|
| 219 | - $public_display['nickname'] = $profileuser->nickname; |
|
| 220 | - $public_display['username'] = $profileuser->user_login; |
|
| 221 | - |
|
| 222 | - if ( !empty($profileuser->first_name) ) { |
|
| 223 | - $public_display['firstname'] = $profileuser->first_name; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - if ( !empty($profileuser->last_name) ) { |
|
| 227 | - $public_display['lastname'] = $profileuser->last_name; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 231 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 232 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $public_display = array_map( 'trim', $public_display ); |
|
| 236 | - $public_display = array_unique( $public_display ); |
|
| 237 | - |
|
| 238 | - return $public_display; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 244 | - * |
|
| 245 | - * @see GFUser::update_user() |
|
| 246 | - * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 247 | - * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 248 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 249 | - * @param string $password User password |
|
| 250 | - * @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 |
|
| 251 | - */ |
|
| 252 | - public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 256 | - * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 257 | - * @since 1.14.4 |
|
| 258 | - * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 259 | - */ |
|
| 260 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 261 | - |
|
| 262 | - $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Don't restore display name: |
|
| 266 | - * - either disabled, |
|
| 267 | - * - or it is an Update feed (we only care about Create feed) |
|
| 268 | - * - or we don't need as we found the correct format before updating user. |
|
| 269 | - * @since 1.14.4 |
|
| 270 | - */ |
|
| 271 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 272 | - return null; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $user_after_update = get_userdata( $user_id ); |
|
| 276 | - |
|
| 277 | - // User not found |
|
| 278 | - if ( ! $user_after_update ) { |
|
| 279 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - User not found at $user_id #%d', $user_id ) ); |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $restored_user = $user_after_update; |
|
| 284 | - |
|
| 285 | - // Restore previous display_name |
|
| 286 | - $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 287 | - |
|
| 288 | - // Don't have WP update the password. |
|
| 289 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 293 | - * @since 1.14 |
|
| 294 | - * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 295 | - * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 296 | - * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 297 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 298 | - */ |
|
| 299 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 300 | - |
|
| 301 | - $updated = wp_update_user( $restored_user ); |
|
| 302 | - |
|
| 303 | - if( is_wp_error( $updated ) ) { |
|
| 304 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
| 305 | - } else { |
|
| 306 | - do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $this->_user_before_update = null; |
|
| 310 | - |
|
| 311 | - unset( $restored_user, $user_after_update ); |
|
| 312 | - |
|
| 313 | - return $updated; |
|
| 314 | - } |
|
| 135 | + public function get_feed_configuration( $entry, $form ) { |
|
| 136 | + |
|
| 137 | + /** @var GF_User_Registration $gf_user_registration */ |
|
| 138 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 139 | + |
|
| 140 | + $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 144 | + * @since 1.15 |
|
| 145 | + * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 146 | + * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 147 | + * @param[in] array $form Gravity Forms form array |
|
| 148 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 149 | + */ |
|
| 150 | + $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 151 | + |
|
| 152 | + if( $preserve_role ) { |
|
| 153 | + $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Make sure the current display name is not changed with the update user method. |
|
| 160 | + * @since 1.15 |
|
| 161 | + */ |
|
| 162 | + $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 166 | + * @since 1.14 |
|
| 167 | + * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 168 | + * @param[in] array $form Gravity Forms form array |
|
| 169 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 170 | + */ |
|
| 171 | + $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 172 | + |
|
| 173 | + return $config; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Calculate the user display name format |
|
| 178 | + * |
|
| 179 | + * @since 1.15 |
|
| 180 | + * @since 1.20 Returns false if user not found at $user_id |
|
| 181 | + * |
|
| 182 | + * @param int $user_id WP User ID |
|
| 183 | + * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 184 | + */ |
|
| 185 | + public function match_current_display_name( $user_id ) { |
|
| 186 | + |
|
| 187 | + $user = get_userdata( $user_id ); |
|
| 188 | + |
|
| 189 | + if( ! $user ) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $names = $this->generate_display_names( $user ); |
|
| 194 | + |
|
| 195 | + $format = array_search( $user->display_name, $names, true ); |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 199 | + * @see restore_display_name |
|
| 200 | + */ |
|
| 201 | + if( false === $format ) { |
|
| 202 | + $this->_user_before_update = $user; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return $format; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Generate an array of all the user display names possibilities |
|
| 210 | + * |
|
| 211 | + * @since 1.15 |
|
| 212 | + * |
|
| 213 | + * @param object $profileuser WP_User object |
|
| 214 | + * @return array List all the possible display names for a certain User object |
|
| 215 | + */ |
|
| 216 | + public function generate_display_names( $profileuser ) { |
|
| 217 | + |
|
| 218 | + $public_display = array(); |
|
| 219 | + $public_display['nickname'] = $profileuser->nickname; |
|
| 220 | + $public_display['username'] = $profileuser->user_login; |
|
| 221 | + |
|
| 222 | + if ( !empty($profileuser->first_name) ) { |
|
| 223 | + $public_display['firstname'] = $profileuser->first_name; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + if ( !empty($profileuser->last_name) ) { |
|
| 227 | + $public_display['lastname'] = $profileuser->last_name; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 231 | + $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 232 | + $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $public_display = array_map( 'trim', $public_display ); |
|
| 236 | + $public_display = array_unique( $public_display ); |
|
| 237 | + |
|
| 238 | + return $public_display; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 244 | + * |
|
| 245 | + * @see GFUser::update_user() |
|
| 246 | + * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 247 | + * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 248 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 249 | + * @param string $password User password |
|
| 250 | + * @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 |
|
| 251 | + */ |
|
| 252 | + public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 256 | + * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 257 | + * @since 1.14.4 |
|
| 258 | + * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 259 | + */ |
|
| 260 | + $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 261 | + |
|
| 262 | + $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Don't restore display name: |
|
| 266 | + * - either disabled, |
|
| 267 | + * - or it is an Update feed (we only care about Create feed) |
|
| 268 | + * - or we don't need as we found the correct format before updating user. |
|
| 269 | + * @since 1.14.4 |
|
| 270 | + */ |
|
| 271 | + if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 272 | + return null; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $user_after_update = get_userdata( $user_id ); |
|
| 276 | + |
|
| 277 | + // User not found |
|
| 278 | + if ( ! $user_after_update ) { |
|
| 279 | + do_action('gravityview_log_error', __METHOD__ . sprintf( ' - User not found at $user_id #%d', $user_id ) ); |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $restored_user = $user_after_update; |
|
| 284 | + |
|
| 285 | + // Restore previous display_name |
|
| 286 | + $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 287 | + |
|
| 288 | + // Don't have WP update the password. |
|
| 289 | + unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 293 | + * @since 1.14 |
|
| 294 | + * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 295 | + * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 296 | + * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 297 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 298 | + */ |
|
| 299 | + $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 300 | + |
|
| 301 | + $updated = wp_update_user( $restored_user ); |
|
| 302 | + |
|
| 303 | + if( is_wp_error( $updated ) ) { |
|
| 304 | + do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
| 305 | + } else { |
|
| 306 | + do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $this->_user_before_update = null; |
|
| 310 | + |
|
| 311 | + unset( $restored_user, $user_after_update ); |
|
| 312 | + |
|
| 313 | + return $updated; |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | } //end class |