[wp-hackers] internal redirects

capsx capsx at team.lv
Tue Apr 27 16:30:25 UTC 2010


Hello all!


I'm quite new to WP, especially to wordpress plugins.
I'm writing plugin which validate posted form (frontpage).

My style that i did that task previous is:

1. after user submit the form, i check posted variables
2. if there are errors i redirect user back to the same 
page, before that i set in session in which there are 
errors
3. code cheks if there are errors or something else to 
show, and if is, it's shows

the problem starts with headers.
in the example above i used technique with ob_start(); and 
ob_end_clean(); in index file, to prevent 'headers already 
sent' error is displaying

but in wordpress it's a bit different ...

at first time my way to complete the task was:

add_shortcode('shortcode', 'asd');
then make function asd() which calls class and class is 
displaying needed information
and in that case i can't use header('location: xxx), cause 
headers are already sent ...

so i made all that in a different way:

my code get slug from wp options and compare it with 
requested page slug
if both are equal - function is called to show my plugin

--

$plugin_call_slug = get_option('_slug');
$requested_uri = base_server('REQUEST_URI'); // == 
$_SERVER['REQUEST_URI']
$requested_page = get_page_by_path( $requested_uri );

$requested_page = $requested_page->post_name;

if($requested_page == $plugin_call_slug)
{
     _function();
}

--

and _function calls class, and that class make all what it 
must do
and all output is stored in variable $return and that 
variable is stored in session variable $ss

and then we call the same function
add_shortcode('shortcode', 'asd');
only now function() is displaying only that variable from 
session variable $ss which hold all output from class 
execution

function asd()
{
     $a = base_session('return');
     echo $a;
}

---

THE QUESTION IS - IS THIS A +/- CORRECT WAY HOW TO MAKE 
INTERNAL REDIRECTS, OR THERE IS OTHER LESS PAINFUL WAYS TO 
MAKE THOSE REDIRECTS AND OUTPUT NEEDED CONTENT... ???

---


thx





More information about the wp-hackers mailing list