WordPress.org

Ready to get started?Download WordPress

Forums

Non WP Rewrite Rule to Admin Screen using plugin (2 posts)

  1. chrismichaels84
    Member
    Posted 9 months ago #

    Howdy all, thanks in advance for your help. I am creating a plugin that uses the administration screen extensively (adapting a rather complex, MVC program to WordPress for Creative Collaboration). I want do use simple urls so that when a user goes to /studio/whatever the url is rewritten to the correct admin screen.

    There is probably a better way to do this. This is the end result that I'm looking for:

    www.example.com/studio/whatever/whatever2

    gets rewritten to:

    www.example.com/wordpress/wp-admin/admin.php?page=_cs&uri=whatever/whatever2

    I've actually gotten this to work with the following code:

    add_action('generate_rewrite_rules', 'cs_rewrite_rules');  
    
    function cs_rewrite_rules() {
      global $wp_rewrite;
      $new_non_wp_rules = array(
        'studio/(.*)'   => 'wordpress/wp-admin/admin.php?page=_cs&uri=$1',
      );
      $wp_rewrite->non_wp_rules += $new_non_wp_rules;
    }

    I've used several analyzers and the URL is being rewritten fine. However, when I run it in wordpress, I am redirected to a login screen. The loop is infinite. I never get to the admin panel. However, if I go there directly, everything works wonderfully.

    There is probably another way to do this. I considered using template_redirect or template_include as discussed in another thread, but neither of those give me the admin credentials or boot process.

    I am stuck and would love some help.

    Thank you,

    Michael.

  2. bcworkz
    Member
    Posted 9 months ago #

    What's happening is the redirect to the login page picks up the original request instead of the rewritten request as the URL to go to once the login completes. Which invokes the login redirect once again, despite the user actually being logged in. Not sure why, but that's what it is.

    How to deal with it is to also hook into the 'login_redirect' filter. If the passed $redirect_to value preg_matches the rewrite rule's, then return the rewritten URL.

    You essentially are rewriting the same request twice, which is odd, but it works.

Reply

You must log in to post.

About this Topic