Skip to content

Commit 7670bfb

Browse files
Timiwahalahti feature archive referrer (#149)
* Add a bit different referrer fields if form is in archive * Do not keep _referrer_archive_title as a additional field if posted from archive * beautiful $current_url when permalink structure is not basic and correct if is * fix phpcs
1 parent b64fa5e commit 7670bfb

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

classes/class-cpt-wplf-form.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,20 @@ class="libre-form libre-form-<?php echo esc_attr( $id . ' ' . $xclass ); ?>"
947947
// @codingStandardsIgnoreStart
948948
echo $content;
949949
// @codingStandardsIgnoreEnd
950-
?>
951-
<input type="hidden" name="referrer" value="<?php the_permalink(); ?>">
952-
<input type="hidden" name="_referrer_id" value="<?php echo esc_attr( get_the_id() ); ?>">
950+
951+
if ( is_archive() ) :
952+
global $wp;
953+
$current_url = home_url( $wp->request );
954+
if ( empty( get_option( 'permalink_structure' ) ) ) {
955+
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
956+
} ?>
957+
<input type="hidden" name="referrer" value="<?php echo esc_attr( $current_url ); ?>">
958+
<input type="hidden" name="_referrer_id" value="archive">
959+
<input type="hidden" name="_referrer_archive_title" value="<?php echo esc_attr( get_the_archive_title() ); ?>">
960+
<?php else : ?>
961+
<input type="hidden" name="referrer" value="<?php the_permalink(); ?>">
962+
<input type="hidden" name="_referrer_id" value="<?php echo esc_attr( get_the_id() ); ?>">
963+
<?php endif; ?>
953964
<input type="hidden" name="_form_id" value="<?php echo esc_attr( $id ); ?>">
954965
</form>
955966
<?php

inc/wplf-form-validation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ function wplf_validate_additional_fields( $return ) {
114114
}
115115
$additional_fields = array_filter( $additional_fields ); // get rid of the empty keys
116116

117+
// support archive referrer, do not keep field _referrer_archive_title as a additional field
118+
if ( 'archive' === $all_fields['_referrer_id'] && array_key_exists( '_refererr_archive_title', $additional_fields ) ) {
119+
unset( $additional_fields['_referrer_archive_title'] );
120+
}
121+
117122
if ( ! empty( $additional_fields ) ) {
118123
$return->ok = 0;
119124
$return->error = __( 'Additional fields are present.', 'wp-libre-form' );

0 commit comments

Comments
 (0)