You can use an action to fire a script prior to a Redirect as follows:
<?php
// for Quick Redirects:
add_action( 'qppr_redirect', 'your_custom_plugin_fire_function' );
// for Individual Redirects:
add_action( 'qppr_do_redirect', 'your_custom_plugin_fire_function' );
// Change 'your_plugin_fire_function' to your script function name.
?>
Then it will trigger JUST prior to the redirect.
If your script is in a class, instead add:
<?php
// for Quick Redirects:
add_action( 'qppr_redirect', array( 'your_class_name', 'your_custom_plugin_fire_function' ) );
// for Individual Redirects:
add_action( 'qppr_do_redirect', array( 'your_class_name', 'your_custom_plugin_fire_function' ) );
// Change 'your_class_name' to your class name and 'your_plugin_fire_function' to your script function name inside your class.
?>
Best of luck,
Don
Should have told you that both actions pass two values – the redirect destination URL and the redirect type (301, 302 etc). If your function does not take a variable then you need to do this differently:
Still add this:
<?php
// for Quick Redirects:
add_action( 'qppr_redirect', 'new_custom_plugin_fire_function' );
// for Individual Redirects:
add_action( 'qppr_do_redirect', 'new_custom_plugin_fire_function' );
function new_custom_plugin_fire_function( $url = '' ){
//call your function here
your_custom_fire_function();
}
?>
Regards,
Don
Thanks Don. Thats helpful. Still can’t quite get it firing though. The main issue is the old site has urls as follows:
News main page
olddomain.com/home/Whatever/News/tabid/1234/Default.aspx
News article
olddomain.com/home/Whatever/News/tabid/1234/Default.aspx?Id=3042
So the new site has more friendly URLs. In my custom plugin I intercept the request and see if it has the pattern /home/Whatever/News/tabid/1234/Default.aspx?Id=3042 and if so it grabs the 3042 and looks it up as a custom field in the other posts.
However in redirecting the main page, to newdomain.com/news from the above URL, it never gets to my script before redirecting.
I am using the redirect list in the plugin settings (not individual page redirects) if that helps at all.
Can you send me the custom plugin you made and I will look at it and see what you need to do to get it working with the redirect plugin?
Send to [email protected].
Regards,
Don
Sure Don. Thanks. I’ll be around later tonight and will send.