Support » Plugin: Quick Page/Post Redirect Plugin » Load priority

  • Resolved stueynet

    (@stueynet)


    I have a custom script in a custom plugin I am using for a number of redirects. These are for news items etc coming from a legacy database. I need to have this script fire BEFORE the redirects from this plugin. Any thoughts on how I can get my custom plugin to run well before this plugin runs?

    https://wordpress.org/plugins/quick-pagepost-redirect-plugin/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Don Fischer

    (@prophecy2040)

    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

    Don Fischer

    (@prophecy2040)

    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

    stueynet

    (@stueynet)

    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.

    Don Fischer

    (@prophecy2040)

    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 plugins@fischercreativemedia.com.

    Regards,
    Don

    stueynet

    (@stueynet)

    Sure Don. Thanks. I’ll be around later tonight and will send.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Load priority’ is closed to new replies.