Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass url params in redirect #52

Closed
joshuadavidnelson opened this issue Oct 29, 2021 · 1 comment · Fixed by #51
Closed

Pass url params in redirect #52

joshuadavidnelson opened this issue Oct 29, 2021 · 1 comment · Fixed by #51
Assignees
Milestone

Comments

@joshuadavidnelson
Copy link
Owner

A request in this WP Support Forum post to allow for front-end redirects to include "utm variables". Likely this would be implemented as a optionally feature (perhaps via a filter and eventually a settings page interface) to pass all url params in front-end redirects.

@joshuadavidnelson
Copy link
Owner Author

This is available in version 0.5.0. You’ll need to add the following line to your theme’s function.php file or a custom plugin file to allow all query vars to be passed on any redirects performed by this plugin:

add_filter( 'dwpb_pass_query_string_on_redirect', '__return_true' );

After enabled you can control this further using the dwpb_allowed_query_vars filter to modify the allowed query vars:

add_filter( 'dwpb_allowed_query_vars', 'issue_52_example_filter_query_vars', 10, 1 );
/**
 * Filter for allowed queary string variables.
 * 
 * This passes an array of the query vars allowed, all others will be removed.
 *
 * @since 0.5.0
 * @param array $allowed_query_vars an array of the allowed query variable keys.
 * @return array
 */
function issue_52_example_filter_query_vars( $allowed_query_vars ) {

	// swap this for your own logic to modify the query vars passed
	// here we're allowing only 'utm' vars.
	$allowed_query_vars = array( 'utm' ); 

	return $allowed_query_vars;

}

Note all query strings are passed through esc_html during the redirect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant