joshuadavidnelson / disable-blog

All the power of WordPress, without a blog. This plugin removes blog related functionality.
https://wordpress.org/plugins/disable-blog/
GNU General Public License v2.0
52 stars 6 forks source link

Pass url params in redirect #52

Closed joshuadavidnelson closed 2 years ago

joshuadavidnelson commented 2 years ago

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 commented 2 years ago

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.