author

Redirects from pop-up windows fail to redirect.

2 months ago | petelingo (Member) | |

Hi folks,

(Warning: Relative novice here)

In my blog, I've created a link that opens a pop-up window containing the WP Write Post screen. (<yoursite>/wp-admin/post-new.php

The idea is to keep the editor window open so I have separate windows, one for reading and the other for editing/writing. Normally in WP, after clicking 'publish', you're redirected to the post index. I don't want that. I want the editor window to remain the editor window so I tried redirecting it to itself. The redirect is setup as follows:

Source URL: mysite/wp-admin/post-new.php
Target URL: mysite/wp-admin/post-new.php

The redirect works, sort of.

Explanation: If I enter the Write Post editor window by typing in the URL in my browser address bar, it works fine. BUT...

Problem: When I click on my pop-up window to open the Write Post editor, the Write Post window opens fine and posts perfectly, BUT the redirection is ignored. It reverts to the default Wordpress functionality and I'm taken to the post index. The redirection doesn't seem to work unless it's come from the browser address bar.

Attempts to find a solution:
I've tried
1. Opening a new window using target="_blank". (Redirection is ignored).
2. Opening a pop-up window using Javascript. (Redirection is ignored).
3. Embedding the Write Post window below my main content using a <DIV>. It embeds fine. I can write and post my entry, no problem. (Redirection is ignored).

Could it be that with all these methods the HTTP header or request is somehow altered?

So far, the upshot is no redirections using any kind of pop-up windows.

Please help!

Thank you and hats off for an otherwise superb plugin.

Pete.

Read responses...

Responses

  1. John:

    Posted 2 months ago by Key Master

    Redirection has built-in protection to stop you redirecting admin pages - people were getting into an awful mess by setting up redirections that would render the plugin unusable. The fact it's working at all is an indication that something wrong is happening rather than there is a problem with the times it's not working!

    Rather than try to use a redirection to change the functionality of WordPress I'd see if there are any plugins that might do the same. Using a redirection may cause unwanted side-effects (possibly things like the auto-save may stop working).

    Redirection doesn't care if a URL is requested from a pop up so I can only imagine the effects you were experiencing was a result of a bug in the admin protection I mentioned.

  2. author
    petelingo:

    Posted 2 months ago by Member

    Hi John,

    Well thank you firstly for your speedy response but I'm afraid the situation has left me feeling a little despondent. The reason being I've exhausted most of the obvious avenues and I've reached the limits of my technical know-how. Yes, I've already searched for plugins to achieve my aim - that's how I stumbled upon your redirection plugin. I've also tried auto-closing the editor window after clicking the publish button in the Write Post editor (using both onSubmit and onClick). The aim being that the user can click the 'editor' link on my blog, which launches an editor pop-up window. They write their post and hit publish. Immediately the editor window is closed and they're left looking at the content window again. Great. So, I added this JS code to the 'post' form in edit-advanced-post.php. The window closes fine. Problem: unfortunately the post never makes it through to publication. It seems obvious that onSubmit would occur before the HTTP post action but it seems the close window action discards the HTTP post request entirely. Why?

    Anyway, the closest I've come to achieving my aim is to use a kind of loop from the post index. Each time the post index loads, (using JS onLoad) I launch the Write Post editor in a new pop-up window. In the editor pop-up window, each time the user publishes a post, by default, he/she is instantaneously redirected by WP to the post index. Here's the interesting bit: when the editor window itself is directed to the post index, what happens? A new editor pop-up window is launched. An infinite loop of pop-up windows? No. Subsequent onLoad events in the child window reuse the same child window. It must be some kind of JS security preventing an infinite loop of endlessly opening pop-up windows that the same window is reused. So, once the Editor pop-up window is opened (as a child), it gets reused with each subsequent publish action. The effect is that it instantaneously whizzes back to the post index and then reloads Editor window, reusing the same child window. In essence, you get a loop.

    It's a far cry from the effect I was hoping for but I'm afraid it's the most success I've had. It could also be very annoying. Sometimes of course, when wanting to read content, you don't always need an editor window. Secondly, if the user is in the middle of a post and refreshes the main content window, the onLoad will trigger a new window event and his/her post in the editor window refreshes itself i.e. their post disappears before it has been published. Inexcusable!

    So, any thoughts on what else I might do? (Suggestions involving toasters in bathtubs might tip me over the edge).

    Thanks mate.

    Pete.

  3. John:

    Posted 2 months ago by Key Master

    Having just tried it, whenever I press publish I am sent back to the post edit screen and not to the post index. This is using WordPress 2.6.2 and should be the default behaviour.

  4. author
    petelingo:

    Posted 2 months ago by Member

    No, unfortunately that's just WP directing you back to the originating page. If you had a link on your blog which spawned a new window, the originator would be still be your blog page. So through the newly-opened window, each time you hit publish, you're always redirected to the blog page. (I've tested it enough times to know. If I knew where it happened in the WP code, I could write a plugin which does this one simple redirect).

  5. author
    petelingo:

    Posted 2 months ago by Member

    Incidentally, I've just tried a fresh install of WP and can confirm the default WP behaviour from the Post editor. Just as mentioned above, it redirects the user back to the originating source of the HTTP request. That's good news for your plugin. My earlier redirects using your plugin were having no effect. Your built-in checks to bypass WP admin pages is working.

  6. John:

    Posted 2 months ago by Key Master

    If you feel up to hacking you could try modifying the core WordPress so as to achieve the effect you want. All the relevant code is in wp-admin/post.php - look out for calls to the function wp_redirect and redirect_post

Reply

You must log in to post.

Home | Software | Terms & Conditions | Sitemap | John Godley © 2008