How can I check if on specific plugin generated page or child

I am writing a function to force a redirect when accessing a certain page.

I have done similar things using code like

Read More
 if ( is_main_query() && 
       ( is_singular($restricted_post_types)||is_single() ) 
       && ! is_user_logged_in() ) { 
           wp_redirect(...) 
 }

But now I want to target a certain class of pages (profile related pages in the bbpress plugin bc Genesis is destroying them). I don’t know what I can use to identify this from an action in the template_redirect hook.

I think anything with the pattern '<baseurl>/forums/user' would catch what I need

Related posts

1 comment

  1. If you’re trying to catch the pattern ‘/forums/user’, you could use PHP’s stringpos function. Something like this should capture what you’re looking for:

    $url_pattern = "/forums/user";
    $requested_uri = $_SERVER["REQUEST_URI"];
    
    if(strpos($requested_uri, $url_pattern) == 0){
        //Your code goes here
    }
    

    Make sure if you have “enforce trailing slashes” set that you use “/forums/user/” as your matching pattern instead. This code isn’t tested but should work.

Comments are closed.