Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter puzz

    (@puzz)

    Hey, look, if this is only for me, don’t worry. I’m not using widgets and I’ll just change the code with template_redirect. You can then fix this without any time pressure when (if) you find the time.

    Thread Starter puzz

    (@puzz)

    The template_redirect isn’t related to any http redirects:

    This action hook executes just before WordPress determines which template page to load.

    I decided to use it (instead of init) because at that point I’m sure that the global $post variable is fully loaded. But if it works with init it’s fine, too.

    • This reply was modified 9 years, 5 months ago by puzz.
    Thread Starter puzz

    (@puzz)

    Ah, and there is another (and slightly better) solution. This will start ob_start() only when it detects that the current $post has your shortcode:

    add_action('template_redirect', 'vscf_check_shortcode');
    function vscf_check_shortcode() {
        global $post;
        if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact') ) {
            ob_start();                                                                                                                                                                                             }
    }

    …and now wp_redirect() will work.

    Thread Starter puzz

    (@puzz)

    Hey, here I am again, I think this should work:

    add_action('init', 'do_output_buffer');
    function do_output_buffer() {
        ob_start();
    }

    …it makes sure no content is sent before you. The content is kept in memory and WordPress makes sure to flush all the ob_ cache later.

    And now wp_redirect() (https://developer.ww.wp.xz.cn/reference/functions/wp_redirect/) can be used from any place in your plugin.

    I’m still reading if that is OK to do from a wp plugin, but it works.

    • This reply was modified 9 years, 5 months ago by puzz.
    • This reply was modified 9 years, 5 months ago by puzz.
    Thread Starter puzz

    (@puzz)

    I caught a bad flu last week and haven’t had the time to experiment with it. If nothing works, I’ll just have to live with it.

    And, don’t worry about my donation. That was for your efforts (and nobody can deny that you work hard, I appreciate that!). If you ever come to Croatia, ping me I owe you a beer for your efforts!

    • This reply was modified 9 years, 5 months ago by puzz.
    Thread Starter puzz

    (@puzz)

    Yeah, that should work. The redirect is slow because it needs to load the page, with header redirect it would be almost instant, I suppose. But, I don’t mind if it’s slow, the only important thing for me is to have this one specified url requested (sooner or later).

    BTW, the cleanest way to do the redirect properly is probably to register a hook like:

    add_action('init', 'your_function');

    This is done before WP starts the output, and you are still in time to send a header there. But I think that would need a bigger refactoring of the code. In the meantime, the javascript redirect is definitely enough for me.

    PS. Just sent a “Thank you” donation. Not huge, but I think it should be enough for a pizza and a beer (maybe even two) in Netherlands πŸ™‚

    Thread Starter puzz

    (@puzz)

    I’m not on my dev machine now, but I’ll try to experiment with it tomorrow.

    Thread Starter puzz

    (@puzz)

    Hey, yes, that’s exactly what I was thinking.

    Anyway, if you need any help just let me know.

    Thread Starter puzz

    (@puzz)

    Yes, that would be perfect!

    Now, I’m not much of an wordpress developer (more into Java/Golang), but I think the normal location() redirect can’t be done from a plugin when part of the page is already sent. At least I think it is. But maybe even a <javascript>document.location=...</javascript> will be enough?

    WP 2.5 here… Don’t work for me πŸ™

Viewing 10 replies - 1 through 10 (of 10 total)