Skip to content

Add a filter to $url in init()#56

Closed
MichaelApproved wants to merge 1 commit into
johngodley:masterfrom
MichaelApproved:patch-1
Closed

Add a filter to $url in init()#56
MichaelApproved wants to merge 1 commit into
johngodley:masterfrom
MichaelApproved:patch-1

Conversation

@MichaelApproved
Copy link
Copy Markdown

By allowing developers to filter the $url, we can customize our installation and avoid complicated regex rules. My sites never care about query variables but we always have to account for them in our redirections with complicated regex statements. By filtering the $url, we can chop off the query part of a URL and never have to deal with it in the redirection rule.

I initially proposed this change and gave examples here https://wordpress.org/support/topic/making-it-easy-to-redirect-without-regex

By allowing developers to filter the $url, we can customize our installation and avoid complicated regex rules. My sites never care about query variables but we always have to account for them in our redirections with complicated regex statements. By filtering the $url, we can chop off the query part of a URL and never have to deal with it in the redirection rule.

I initially proposed this change and gave examples here https://wordpress.org/support/topic/making-it-easy-to-redirect-without-regex
@taeo
Copy link
Copy Markdown

taeo commented May 5, 2015

+1

@MichaelApproved
Copy link
Copy Markdown
Author

My theme code would look something like this

add_filter('redirection_url', 'redirection_url_filter_simplify_url', 10);
function redirection_url_filter_simplify_url($url) {
    $simple_url = $url;
    $simple_url = explode("?", $simple_url);
    $simple_url = $simple_url[0];

    return $simple_url;
}

@taeo
Copy link
Copy Markdown

taeo commented May 5, 2015

That would be nice, allowing ^\/page-slug\/ instead of ^\/page-slug($|\?+.*|\/+.*)

@MichaelApproved
Copy link
Copy Markdown
Author

That's right @taeo and another bonus with this filter is that developers could strtolower the entire $url, so it'll be easy to have case insensitive matches without regex. Hope this gets merged. It'll make our life so much simpler.

@npgdevelopment
Copy link
Copy Markdown

Waiting for this feature too.

+1

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants