@@ -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 | |
@@ -13,12 +13,12 @@ discard block |
||
| 13 | 13 | $base_url = GravityView_Widget_Search::get_search_form_action(); |
| 14 | 14 | |
| 15 | 15 | // Make sure that there are choices to display |
| 16 | -if ( empty( $search_field['choices'] ) ) { |
|
| 16 | +if ( empty( $search_field[ 'choices' ] ) ) { |
|
| 17 | 17 | gravityview()->log->debug( 'search-field-link.php - No choices for field' ); |
| 18 | 18 | return; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | -$links_label = empty( $search_field['label'] ) ? __( 'Show only:', 'gravityview' ) : $search_field['label']; |
|
| 21 | +$links_label = empty( $search_field[ 'label' ] ) ? __( 'Show only:', 'gravityview' ) : $search_field[ 'label' ]; |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @filter `gravityview/extension/search/links_label` Change the label for the "Link" search bar input type |
@@ -41,24 +41,24 @@ discard block |
||
| 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 | 48 | if ( 0 != $k ) { |
| 49 | 49 | echo esc_html( $links_sep ); |
| 50 | 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 | 54 | if ( $active ) { |
| 55 | - $link = remove_query_arg( array( 'pagenum', $search_field['name'] ), $base_url ); |
|
| 55 | + $link = remove_query_arg( array( 'pagenum', $search_field[ 'name' ] ), $base_url ); |
|
| 56 | 56 | } else { |
| 57 | - $link = add_query_arg( array( $search_field['name'] => urlencode( $choice['value'] ) ), remove_query_arg( array('pagenum'), $base_url ) ); |
|
| 57 | + $link = add_query_arg( array( $search_field[ 'name' ] => urlencode( $choice[ 'value' ] ) ), remove_query_arg( array( 'pagenum' ), $base_url ) ); |
|
| 58 | 58 | } |
| 59 | 59 | ?> |
| 60 | 60 | |
| 61 | - <a href="<?php echo esc_url_raw( $link ); ?>" <?php echo $active; ?>><?php echo esc_html( $choice['text'] ); ?></a> |
|
| 61 | + <a href="<?php echo esc_url_raw( $link ); ?>" <?php echo $active; ?>><?php echo esc_html( $choice[ 'text' ] ); ?></a> |
|
| 62 | 62 | |
| 63 | 63 | <?php } ?> |
| 64 | 64 | </p> |
@@ -10,22 +10,22 @@ |
||
| 10 | 10 | $search_field = $gravityview_view->search_field; |
| 11 | 11 | |
| 12 | 12 | // Make sure that there are choices to display |
| 13 | -if( empty( $search_field['choices'] ) ) { |
|
| 13 | +if ( empty( $search_field[ 'choices' ] ) ) { |
|
| 14 | 14 | gravityview()->log->debug( 'search-field-checkbox.php - No choices for field' ); |
| 15 | 15 | return; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | ?> |
| 19 | 19 | <div class="gv-search-box gv-search-field-checkbox"> |
| 20 | - <?php if( ! gv_empty( $search_field['label'], false, false ) ) { ?> |
|
| 21 | - <label for=search-box-<?php echo esc_attr( $search_field['name'] ); ?>><?php echo esc_html( $search_field['label'] ); ?></label> |
|
| 20 | + <?php if ( ! gv_empty( $search_field[ 'label' ], false, false ) ) { ?> |
|
| 21 | + <label for=search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>><?php echo esc_html( $search_field[ 'label' ] ); ?></label> |
|
| 22 | 22 | <?php } ?> |
| 23 | 23 | <p> |
| 24 | - <?php foreach( $search_field['choices'] as $choice ) { ?> |
|
| 24 | + <?php foreach ( $search_field[ 'choices' ] as $choice ) { ?> |
|
| 25 | 25 | |
| 26 | - <label for="search-box-<?php echo sanitize_html_class( $search_field['name'].$choice['value'].$choice['text'] ); ?>" class="gv-check-radio"> |
|
| 27 | - <input type="checkbox" name="<?php echo esc_attr( $search_field['name'] ); ?>[]" value="<?php echo esc_attr( $choice['value'] ); ?>" id="search-box-<?php echo sanitize_html_class( $search_field['name'].$choice['value'].$choice['text'] ); ?>" <?php gv_selected( $choice['value'], $search_field['value'], true, 'checked' ); ?>> |
|
| 28 | - <?php echo esc_html( $choice['text'] ); ?> |
|
| 26 | + <label for="search-box-<?php echo sanitize_html_class( $search_field[ 'name' ] . $choice[ 'value' ] . $choice[ 'text' ] ); ?>" class="gv-check-radio"> |
|
| 27 | + <input type="checkbox" name="<?php echo esc_attr( $search_field[ 'name' ] ); ?>[]" value="<?php echo esc_attr( $choice[ 'value' ] ); ?>" id="search-box-<?php echo sanitize_html_class( $search_field[ 'name' ] . $choice[ 'value' ] . $choice[ 'text' ] ); ?>" <?php gv_selected( $choice[ 'value' ], $search_field[ 'value' ], true, 'checked' ); ?>> |
|
| 28 | + <?php echo esc_html( $choice[ 'text' ] ); ?> |
|
| 29 | 29 | </label> |
| 30 | 30 | |
| 31 | 31 | <?php } ?> |
@@ -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> |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | do_action( 'gravityview_search_widget_fields_before', $this ); |
| 28 | 28 | |
| 29 | - foreach( array_merge( $this->search_fields, $this->permalink_fields ) as $search_field ) { |
|
| 29 | + foreach ( array_merge( $this->search_fields, $this->permalink_fields ) as $search_field ) { |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * @action `gravityview_search_widget_field_before` Before each search input is rendered (other than the submit button) |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | do_action( 'gravityview_search_widget_field_before', $this, $search_field ); |
| 37 | 37 | |
| 38 | 38 | $gravityview_view->search_field = $search_field; |
| 39 | - $this->render( 'search-field', $search_field['input'], false ); |
|
| 39 | + $this->render( 'search-field', $search_field[ 'input' ], false ); |
|
| 40 | 40 | |
| 41 | 41 | // show/hide the search button if there are input type fields |
| 42 | - if( !$has_inputs && $search_field['input'] != 'link' ) { |
|
| 42 | + if ( ! $has_inputs && $search_field[ 'input' ] != 'link' ) { |
|
| 43 | 43 | $has_inputs = true; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | do_action( 'gravityview_search_widget_fields_after', $this ); |
| 59 | 59 | |
| 60 | - if( $has_inputs ) { |
|
| 60 | + if ( $has_inputs ) { |
|
| 61 | 61 | $this->render( 'search-field', 'submit', false ); |
| 62 | 62 | } |
| 63 | 63 | ?> |
@@ -10,22 +10,22 @@ |
||
| 10 | 10 | $search_field = $gravityview_view->search_field; |
| 11 | 11 | |
| 12 | 12 | // Make sure that there are choices to display |
| 13 | -if( empty( $search_field['choices'] ) ) { |
|
| 13 | +if ( empty( $search_field[ 'choices' ] ) ) { |
|
| 14 | 14 | gravityview()->log->debug( 'search-field-radio.php - No choices for field' ); |
| 15 | 15 | return; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | ?> |
| 19 | 19 | <div class="gv-search-box gv-search-field-radio"> |
| 20 | - <?php if( ! gv_empty( $search_field['label'], false, false ) ) { ?> |
|
| 21 | - <label for=search-box-<?php echo esc_attr( $search_field['name'] ); ?>><?php echo esc_html( $search_field['label'] ); ?></label> |
|
| 20 | + <?php if ( ! gv_empty( $search_field[ 'label' ], false, false ) ) { ?> |
|
| 21 | + <label for=search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>><?php echo esc_html( $search_field[ 'label' ] ); ?></label> |
|
| 22 | 22 | <?php } ?> |
| 23 | 23 | <p> |
| 24 | - <?php foreach( $search_field['choices'] as $choice ) { ?> |
|
| 24 | + <?php foreach ( $search_field[ 'choices' ] as $choice ) { ?> |
|
| 25 | 25 | |
| 26 | - <label for="search-box-<?php echo sanitize_html_class( $search_field['name'].$choice['value'].$choice['text'] ); ?>" class="gv-check-radio"> |
|
| 27 | - <input type="radio" name="<?php echo esc_attr( $search_field['name'] ); ?>" value="<?php echo esc_attr( $choice['value'] ); ?>" id="search-box-<?php echo sanitize_html_class( $search_field['name'].$choice['value'].$choice['text'] ); ?>" <?php checked( $choice['value'], $search_field['value'], true ); ?>> |
|
| 28 | - <?php echo esc_html( $choice['text'] ); ?> |
|
| 26 | + <label for="search-box-<?php echo sanitize_html_class( $search_field[ 'name' ] . $choice[ 'value' ] . $choice[ 'text' ] ); ?>" class="gv-check-radio"> |
|
| 27 | + <input type="radio" name="<?php echo esc_attr( $search_field[ 'name' ] ); ?>" value="<?php echo esc_attr( $choice[ 'value' ] ); ?>" id="search-box-<?php echo sanitize_html_class( $search_field[ 'name' ] . $choice[ 'value' ] . $choice[ 'text' ] ); ?>" <?php checked( $choice[ 'value' ], $search_field[ 'value' ], true ); ?>> |
|
| 28 | + <?php echo esc_html( $choice[ 'text' ] ); ?> |
|
| 29 | 29 | </label> |
| 30 | 30 | |
| 31 | 31 | <?php } ?> |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | $search_field = $gravityview_view->search_field; |
| 11 | 11 | |
| 12 | 12 | // Make sure that there are choices to display |
| 13 | -if( empty( $search_field['choices'] ) ) { |
|
| 13 | +if ( empty( $search_field[ 'choices' ] ) ) { |
|
| 14 | 14 | gravityview()->log->debug( 'search-field-multiselect.php - No choices for field' ); |
| 15 | 15 | return; |
| 16 | 16 | } |
@@ -21,19 +21,19 @@ discard block |
||
| 21 | 21 | * @param string $default_option Default: `—` (—) |
| 22 | 22 | * @param string $field_type Field type: "select" or "multiselect" |
| 23 | 23 | */ |
| 24 | -$default_option = apply_filters('gravityview/extension/search/select_default', '—', 'multiselect' ); |
|
| 24 | +$default_option = apply_filters( 'gravityview/extension/search/select_default', '—', 'multiselect' ); |
|
| 25 | 25 | |
| 26 | 26 | ?> |
| 27 | 27 | <div class="gv-search-box gv-search-field-multiselect"> |
| 28 | - <?php if( ! gv_empty( $search_field['label'], false, false ) ) { ?> |
|
| 29 | - <label for="search-box-<?php echo esc_attr( $search_field['name'] ); ?>"><?php echo esc_html( $search_field['label'] ); ?></label> |
|
| 28 | + <?php if ( ! gv_empty( $search_field[ 'label' ], false, false ) ) { ?> |
|
| 29 | + <label for="search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>"><?php echo esc_html( $search_field[ 'label' ] ); ?></label> |
|
| 30 | 30 | <?php } ?> |
| 31 | 31 | <p> |
| 32 | - <select name="<?php echo esc_attr( $search_field['name'] ); ?>[]" id="search-box-<?php echo esc_attr( $search_field['name'] ); ?>" multiple> |
|
| 33 | - <option value="" <?php gv_selected( '', $search_field['value'], true ); ?>><?php echo esc_html( $default_option ); ?></option> |
|
| 32 | + <select name="<?php echo esc_attr( $search_field[ 'name' ] ); ?>[]" id="search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>" multiple> |
|
| 33 | + <option value="" <?php gv_selected( '', $search_field[ 'value' ], true ); ?>><?php echo esc_html( $default_option ); ?></option> |
|
| 34 | 34 | <?php |
| 35 | - foreach( $search_field['choices'] as $choice ) : ?> |
|
| 36 | - <option value="<?php echo esc_attr( $choice['value'] ); ?>" <?php gv_selected( $choice['value'], $search_field['value'], true ); ?>><?php echo esc_html( $choice['text'] ); ?></option> |
|
| 35 | + foreach ( $search_field[ 'choices' ] as $choice ) : ?> |
|
| 36 | + <option value="<?php echo esc_attr( $choice[ 'value' ] ); ?>" <?php gv_selected( $choice[ 'value' ], $search_field[ 'value' ], true ); ?>><?php echo esc_html( $choice[ 'text' ] ); ?></option> |
|
| 37 | 37 | <?php endforeach; ?> |
| 38 | 38 | </select> |
| 39 | 39 | </p> |
@@ -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 |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | ?> |
| 9 | 9 | <label for="<?php echo $this->get_field_id(); ?>" class="<?php echo $this->get_label_class(); ?>"><?php |
| 10 | 10 | |
| 11 | - echo '<span class="gv-label">'.$this->get_field_label().'</span>'; |
|
| 11 | + echo '<span class="gv-label">' . $this->get_field_label() . '</span>'; |
|
| 12 | 12 | echo $this->get_tooltip() . $this->get_field_desc(); |
| 13 | 13 | ?><div> |
| 14 | 14 | <?php $this->render_input(); ?> |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | function render_input( $override_input = null ) { |
| 21 | 21 | |
| 22 | - if( isset( $override_input ) ) { |
|
| 22 | + if ( isset( $override_input ) ) { |
|
| 23 | 23 | echo $override_input; |
| 24 | 24 | return; |
| 25 | 25 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 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' ) { |
|
| 31 | + if ( $show_mt && $this->field[ 'merge_tags' ] !== false || $this->field[ 'merge_tags' ] === 'force' ) { |
|
| 32 | 32 | $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
| 33 | 33 | } |
| 34 | 34 | $class .= \GV\Utils::get( $this->field, 'class', 'widefat' ); |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * @param array $callback_args Arguments passed to the callback |
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | - function __construct( $id, $title = '', $file = '', $icon_class_name = '', $callback = '', $callback_args = array() ) { |
|
| 100 | + function __construct( $id, $title = '', $file = '', $icon_class_name = '', $callback = '', $callback_args = array() ) { |
|
| 101 | 101 | |
| 102 | - $this->id = $this->prefix.$id; |
|
| 102 | + $this->id = $this->prefix . $id; |
|
| 103 | 103 | $this->title = $title; |
| 104 | 104 | $this->render_template_file = $file; |
| 105 | 105 | $this->callback = $callback; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | function parse_icon_class_name( $icon_class_name = '' ) { |
| 120 | 120 | |
| 121 | - if( preg_match( '/dashicon/i', $icon_class_name ) ) { |
|
| 121 | + if ( preg_match( '/dashicon/i', $icon_class_name ) ) { |
|
| 122 | 122 | $icon_class_name = 'dashicons ' . $icon_class_name; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -142,29 +142,29 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | function render( $post ) { |
| 144 | 144 | |
| 145 | - if( !empty( $this->render_template_file ) ) { |
|
| 145 | + if ( ! empty( $this->render_template_file ) ) { |
|
| 146 | 146 | |
| 147 | 147 | $file = $this->render_template_file; |
| 148 | 148 | |
| 149 | 149 | // If the full path exists, use it |
| 150 | - if( file_exists( $file ) ) { |
|
| 150 | + if ( file_exists( $file ) ) { |
|
| 151 | 151 | $path = $file; |
| 152 | 152 | } else { |
| 153 | - $path = GRAVITYVIEW_DIR .'includes/admin/metaboxes/views/'.$file; |
|
| 153 | + $path = GRAVITYVIEW_DIR . 'includes/admin/metaboxes/views/' . $file; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if( file_exists( $path ) ) { |
|
| 156 | + if ( file_exists( $path ) ) { |
|
| 157 | 157 | include $path; |
| 158 | 158 | } else { |
| 159 | 159 | gravityview()->log->error( 'Metabox template file not found', array( 'data' => $this ) ); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - } else if( !empty( $this->callback ) ) { |
|
| 162 | + } else if ( ! empty( $this->callback ) ) { |
|
| 163 | 163 | |
| 164 | - if( is_callable( $this->callback ) ) { |
|
| 164 | + if ( is_callable( $this->callback ) ) { |
|
| 165 | 165 | |
| 166 | 166 | /** @see do_accordion_sections() */ |
| 167 | - call_user_func( $this->callback, $post, (array) $this ); |
|
| 167 | + call_user_func( $this->callback, $post, (array)$this ); |
|
| 168 | 168 | |
| 169 | 169 | } else { |
| 170 | 170 | gravityview()->log->error( 'Metabox callback was not callable', array( 'data' => $this ) ); |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * @since 1.11 |
| 53 | 53 | * @param boolean $boolean Whether to trigger update on user registration (default: true) |
| 54 | 54 | */ |
| 55 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 55 | + if ( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 56 | 56 | |
| 57 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
| 57 | + add_action( 'gravityview/edit_entry/after_update', array( $this, 'update_user' ), 10, 2 ); |
|
| 58 | 58 | |
| 59 | 59 | // last resort in case the current user display name don't match any of the defaults |
| 60 | 60 | add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function update_user( $form = array(), $entry_id = 0 ) { |
| 74 | 74 | |
| 75 | - if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 75 | + if ( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 76 | 76 | gravityview()->log->error( 'GFAPI or User Registration class not found; not updating the user' ); |
| 77 | 77 | return; |
| 78 | - } elseif( empty( $entry_id ) ) { |
|
| 78 | + } elseif ( empty( $entry_id ) ) { |
|
| 79 | 79 | gravityview()->log->error( 'Entry ID is empty [{entry_id}]; not updating the user', array( 'entry_id' => $entry_id ) ); |
| 80 | 80 | return; |
| 81 | 81 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | // If an Update feed, make sure the conditions are met. |
| 104 | 104 | if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
| 105 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 105 | + if ( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | 106 | return; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | remove_filter( 'send_email_change_email', '__return_false', 3 ); |
| 119 | 119 | |
| 120 | 120 | // Prevent double-triggering by removing the hook |
| 121 | - remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 121 | + remove_action( 'gravityview/edit_entry/after_update', array( $this, 'update_user' ), 10 ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -151,17 +151,17 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
| 153 | 153 | |
| 154 | - if( $preserve_role ) { |
|
| 155 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 154 | + if ( $preserve_role ) { |
|
| 155 | + $config[ 'meta' ][ 'role' ] = 'gfur_preserve_role'; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 158 | + $displayname = $this->match_current_display_name( $entry[ 'created_by' ] ); |
|
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | 161 | * Make sure the current display name is not changed with the update user method. |
| 162 | 162 | * @since 1.15 |
| 163 | 163 | */ |
| 164 | - $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 164 | + $config[ 'meta' ][ 'displayname' ] = $displayname ? $displayname : $config[ 'meta' ][ 'displayname' ]; |
|
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $user = get_userdata( $user_id ); |
| 190 | 190 | |
| 191 | - if( ! $user ) { |
|
| 191 | + if ( ! $user ) { |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
| 201 | 201 | * @see restore_display_name |
| 202 | 202 | */ |
| 203 | - if( false === $format ) { |
|
| 203 | + if ( false === $format ) { |
|
| 204 | 204 | $this->_user_before_update = $user; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -218,20 +218,20 @@ discard block |
||
| 218 | 218 | public function generate_display_names( $profileuser ) { |
| 219 | 219 | |
| 220 | 220 | $public_display = array(); |
| 221 | - $public_display['nickname'] = $profileuser->nickname; |
|
| 222 | - $public_display['username'] = $profileuser->user_login; |
|
| 221 | + $public_display[ 'nickname' ] = $profileuser->nickname; |
|
| 222 | + $public_display[ 'username' ] = $profileuser->user_login; |
|
| 223 | 223 | |
| 224 | - if ( !empty($profileuser->first_name) ) { |
|
| 225 | - $public_display['firstname'] = $profileuser->first_name; |
|
| 224 | + if ( ! empty( $profileuser->first_name ) ) { |
|
| 225 | + $public_display[ 'firstname' ] = $profileuser->first_name; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if ( !empty($profileuser->last_name) ) { |
|
| 229 | - $public_display['lastname'] = $profileuser->last_name; |
|
| 228 | + if ( ! empty( $profileuser->last_name ) ) { |
|
| 229 | + $public_display[ 'lastname' ] = $profileuser->last_name; |
|
| 230 | 230 | } |
| 231 | 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; |
|
| 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 | 235 | } |
| 236 | 236 | |
| 237 | 237 | $public_display = array_map( 'trim', $public_display ); |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * - or we don't need as we found the correct format before updating user. |
| 271 | 271 | * @since 1.14.4 |
| 272 | 272 | */ |
| 273 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 273 | + if ( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 274 | 274 | return null; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | $updated = wp_update_user( $restored_user ); |
| 304 | 304 | |
| 305 | - if( is_wp_error( $updated ) ) { |
|
| 305 | + if ( is_wp_error( $updated ) ) { |
|
| 306 | 306 | gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
| 307 | 307 | } else { |
| 308 | 308 | gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
@@ -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,109 +22,109 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @var GravityView_Edit_Entry $loader |
| 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 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 84 | - |
|
| 85 | - $entry = GFAPI::get_entry( $entry_id ); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 89 | - * @since 1.11 |
|
| 90 | - * @param array $entry Gravity Forms entry |
|
| 91 | - * @param array $form Gravity Forms form |
|
| 92 | - */ |
|
| 93 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 94 | - |
|
| 95 | - $config = $this->get_feed_configuration( $entry, $form ); |
|
| 96 | - |
|
| 97 | - // Make sure the feed is active |
|
| 98 | - 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' ); |
|
| 99 | 77 | return; |
| 100 | - } |
|
| 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 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 84 | + |
|
| 85 | + $entry = GFAPI::get_entry( $entry_id ); |
|
| 101 | 86 | |
| 102 | - // If an Update feed, make sure the conditions are met. |
|
| 103 | - if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
|
| 104 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - } |
|
| 87 | + /** |
|
| 88 | + * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 89 | + * @since 1.11 |
|
| 90 | + * @param array $entry Gravity Forms entry |
|
| 91 | + * @param array $form Gravity Forms form |
|
| 92 | + */ |
|
| 93 | + $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 108 | 94 | |
| 109 | - // Do not update user if the user hasn't been registered (happens when manual activation is enabled in User Registration feed) |
|
| 110 | - $username = \GV\Utils::get( $config, 'meta/username', null ); |
|
| 111 | - if ( ! isset( $entry[ $username ] ) || ! get_user_by( 'login', $entry[ $username ] ) ) { |
|
| 112 | - return; |
|
| 113 | - } |
|
| 95 | + $config = $this->get_feed_configuration( $entry, $form ); |
|
| 96 | + |
|
| 97 | + // Make sure the feed is active |
|
| 98 | + if ( ! \GV\Utils::get( $config, 'is_active', false ) ) { |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // If an Update feed, make sure the conditions are met. |
|
| 103 | + if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
|
| 104 | + if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Do not update user if the user hasn't been registered (happens when manual activation is enabled in User Registration feed) |
|
| 110 | + $username = \GV\Utils::get( $config, 'meta/username', null ); |
|
| 111 | + if ( ! isset( $entry[ $username ] ) || ! get_user_by( 'login', $entry[ $username ] ) ) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - // The priority is set to 3 so that default priority (10) will still override it |
|
| 116 | - add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 117 | - add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 115 | + // The priority is set to 3 so that default priority (10) will still override it |
|
| 116 | + add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 117 | + add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 118 | 118 | |
| 119 | - // Trigger the User Registration update user method |
|
| 120 | - $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 119 | + // Trigger the User Registration update user method |
|
| 120 | + $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 121 | 121 | |
| 122 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 123 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 122 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 123 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 124 | 124 | |
| 125 | - // Prevent double-triggering by removing the hook |
|
| 126 | - remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 127 | - } |
|
| 125 | + // Prevent double-triggering by removing the hook |
|
| 126 | + remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * Get the User Registration feed configuration for the entry & form |
@@ -139,184 +139,184 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return array |
| 141 | 141 | */ |
| 142 | - public function get_feed_configuration( $entry, $form ) { |
|
| 143 | - |
|
| 144 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 145 | - |
|
| 146 | - $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 150 | - * @since 1.15 |
|
| 151 | - * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 152 | - * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 153 | - * @param[in] array $form Gravity Forms form array |
|
| 154 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 155 | - */ |
|
| 156 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 157 | - |
|
| 158 | - if( $preserve_role ) { |
|
| 159 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Make sure the current display name is not changed with the update user method. |
|
| 166 | - * @since 1.15 |
|
| 167 | - */ |
|
| 168 | - $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 172 | - * @since 1.14 |
|
| 173 | - * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 174 | - * @param[in] array $form Gravity Forms form array |
|
| 175 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 176 | - */ |
|
| 177 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 178 | - |
|
| 179 | - return $config; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Calculate the user display name format |
|
| 184 | - * |
|
| 185 | - * @since 1.15 |
|
| 186 | - * @since 1.20 Returns false if user not found at $user_id |
|
| 187 | - * |
|
| 188 | - * @param int $user_id WP User ID |
|
| 189 | - * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 190 | - */ |
|
| 191 | - public function match_current_display_name( $user_id ) { |
|
| 192 | - |
|
| 193 | - $user = get_userdata( $user_id ); |
|
| 194 | - |
|
| 195 | - if( ! $user ) { |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $names = $this->generate_display_names( $user ); |
|
| 200 | - |
|
| 201 | - $format = array_search( $user->display_name, $names, true ); |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 205 | - * @see restore_display_name |
|
| 206 | - */ |
|
| 207 | - if( false === $format ) { |
|
| 208 | - $this->_user_before_update = $user; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return $format; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Generate an array of all the user display names possibilities |
|
| 216 | - * |
|
| 217 | - * @since 1.15 |
|
| 218 | - * |
|
| 219 | - * @param object $profileuser WP_User object |
|
| 220 | - * @return array List all the possible display names for a certain User object |
|
| 221 | - */ |
|
| 222 | - public function generate_display_names( $profileuser ) { |
|
| 223 | - |
|
| 224 | - $public_display = array(); |
|
| 225 | - $public_display['nickname'] = $profileuser->nickname; |
|
| 226 | - $public_display['username'] = $profileuser->user_login; |
|
| 227 | - |
|
| 228 | - if ( !empty($profileuser->first_name) ) { |
|
| 229 | - $public_display['firstname'] = $profileuser->first_name; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - if ( !empty($profileuser->last_name) ) { |
|
| 233 | - $public_display['lastname'] = $profileuser->last_name; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 237 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 238 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $public_display = array_map( 'trim', $public_display ); |
|
| 242 | - $public_display = array_unique( $public_display ); |
|
| 243 | - |
|
| 244 | - return $public_display; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 250 | - * |
|
| 251 | - * @see GFUser::update_user() |
|
| 252 | - * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 253 | - * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 254 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 255 | - * @param string $password User password |
|
| 256 | - * @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 |
|
| 257 | - */ |
|
| 258 | - public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 262 | - * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 263 | - * @since 1.14.4 |
|
| 264 | - * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 265 | - */ |
|
| 266 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 267 | - |
|
| 268 | - $is_update_feed = ( $config && \GV\Utils::get( $config, 'meta/feed_type' ) === 'update' ); |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Don't restore display name: |
|
| 272 | - * - either disabled, |
|
| 273 | - * - or it is an Update feed (we only care about Create feed) |
|
| 274 | - * - or we don't need as we found the correct format before updating user. |
|
| 275 | - * @since 1.14.4 |
|
| 276 | - */ |
|
| 277 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 278 | - return null; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - $user_after_update = get_userdata( $user_id ); |
|
| 282 | - |
|
| 283 | - // User not found |
|
| 284 | - if ( ! $user_after_update ) { |
|
| 285 | - gravityview()->log->error( 'User not found at $user_id #{user_id}', array( 'user_id' => $user_id ) ); |
|
| 286 | - return false; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - $restored_user = $user_after_update; |
|
| 290 | - |
|
| 291 | - // Restore previous display_name |
|
| 292 | - $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 293 | - |
|
| 294 | - // Don't have WP update the password. |
|
| 295 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 299 | - * @since 1.14 |
|
| 300 | - * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 301 | - * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 302 | - * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 303 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 304 | - */ |
|
| 305 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 306 | - |
|
| 307 | - $updated = wp_update_user( $restored_user ); |
|
| 308 | - |
|
| 309 | - if( is_wp_error( $updated ) ) { |
|
| 310 | - gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
|
| 311 | - } else { |
|
| 312 | - gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $this->_user_before_update = null; |
|
| 316 | - |
|
| 317 | - unset( $restored_user, $user_after_update ); |
|
| 318 | - |
|
| 319 | - return $updated; |
|
| 320 | - } |
|
| 142 | + public function get_feed_configuration( $entry, $form ) { |
|
| 143 | + |
|
| 144 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 145 | + |
|
| 146 | + $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 150 | + * @since 1.15 |
|
| 151 | + * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 152 | + * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 153 | + * @param[in] array $form Gravity Forms form array |
|
| 154 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 155 | + */ |
|
| 156 | + $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 157 | + |
|
| 158 | + if( $preserve_role ) { |
|
| 159 | + $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Make sure the current display name is not changed with the update user method. |
|
| 166 | + * @since 1.15 |
|
| 167 | + */ |
|
| 168 | + $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 172 | + * @since 1.14 |
|
| 173 | + * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 174 | + * @param[in] array $form Gravity Forms form array |
|
| 175 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 176 | + */ |
|
| 177 | + $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 178 | + |
|
| 179 | + return $config; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Calculate the user display name format |
|
| 184 | + * |
|
| 185 | + * @since 1.15 |
|
| 186 | + * @since 1.20 Returns false if user not found at $user_id |
|
| 187 | + * |
|
| 188 | + * @param int $user_id WP User ID |
|
| 189 | + * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 190 | + */ |
|
| 191 | + public function match_current_display_name( $user_id ) { |
|
| 192 | + |
|
| 193 | + $user = get_userdata( $user_id ); |
|
| 194 | + |
|
| 195 | + if( ! $user ) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $names = $this->generate_display_names( $user ); |
|
| 200 | + |
|
| 201 | + $format = array_search( $user->display_name, $names, true ); |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 205 | + * @see restore_display_name |
|
| 206 | + */ |
|
| 207 | + if( false === $format ) { |
|
| 208 | + $this->_user_before_update = $user; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return $format; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Generate an array of all the user display names possibilities |
|
| 216 | + * |
|
| 217 | + * @since 1.15 |
|
| 218 | + * |
|
| 219 | + * @param object $profileuser WP_User object |
|
| 220 | + * @return array List all the possible display names for a certain User object |
|
| 221 | + */ |
|
| 222 | + public function generate_display_names( $profileuser ) { |
|
| 223 | + |
|
| 224 | + $public_display = array(); |
|
| 225 | + $public_display['nickname'] = $profileuser->nickname; |
|
| 226 | + $public_display['username'] = $profileuser->user_login; |
|
| 227 | + |
|
| 228 | + if ( !empty($profileuser->first_name) ) { |
|
| 229 | + $public_display['firstname'] = $profileuser->first_name; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + if ( !empty($profileuser->last_name) ) { |
|
| 233 | + $public_display['lastname'] = $profileuser->last_name; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 237 | + $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 238 | + $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $public_display = array_map( 'trim', $public_display ); |
|
| 242 | + $public_display = array_unique( $public_display ); |
|
| 243 | + |
|
| 244 | + return $public_display; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 250 | + * |
|
| 251 | + * @see GFUser::update_user() |
|
| 252 | + * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 253 | + * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 254 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 255 | + * @param string $password User password |
|
| 256 | + * @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 |
|
| 257 | + */ |
|
| 258 | + public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 262 | + * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 263 | + * @since 1.14.4 |
|
| 264 | + * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 265 | + */ |
|
| 266 | + $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 267 | + |
|
| 268 | + $is_update_feed = ( $config && \GV\Utils::get( $config, 'meta/feed_type' ) === 'update' ); |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Don't restore display name: |
|
| 272 | + * - either disabled, |
|
| 273 | + * - or it is an Update feed (we only care about Create feed) |
|
| 274 | + * - or we don't need as we found the correct format before updating user. |
|
| 275 | + * @since 1.14.4 |
|
| 276 | + */ |
|
| 277 | + if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 278 | + return null; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + $user_after_update = get_userdata( $user_id ); |
|
| 282 | + |
|
| 283 | + // User not found |
|
| 284 | + if ( ! $user_after_update ) { |
|
| 285 | + gravityview()->log->error( 'User not found at $user_id #{user_id}', array( 'user_id' => $user_id ) ); |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + $restored_user = $user_after_update; |
|
| 290 | + |
|
| 291 | + // Restore previous display_name |
|
| 292 | + $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 293 | + |
|
| 294 | + // Don't have WP update the password. |
|
| 295 | + unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 299 | + * @since 1.14 |
|
| 300 | + * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 301 | + * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 302 | + * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 303 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 304 | + */ |
|
| 305 | + $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 306 | + |
|
| 307 | + $updated = wp_update_user( $restored_user ); |
|
| 308 | + |
|
| 309 | + if( is_wp_error( $updated ) ) { |
|
| 310 | + gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
|
| 311 | + } else { |
|
| 312 | + gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $this->_user_before_update = null; |
|
| 316 | + |
|
| 317 | + unset( $restored_user, $user_after_update ); |
|
| 318 | + |
|
| 319 | + return $updated; |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | 322 | } //end class |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | static function getInstance() { |
| 43 | 43 | gravityview()->log->notice( '\GravityView_oEmbed is deprecated. Use \GV\oEmbed instead.' ); |
| 44 | 44 | |
| 45 | - if( empty( self::$instance ) ) { |
|
| 45 | + if ( empty( self::$instance ) ) { |
|
| 46 | 46 | self::$instance = new self; |
| 47 | 47 | self::$instance->initialize(); |
| 48 | 48 | } |