yaronguez / um-resend-activation-form

Ultimate Member Resend Activation Form - WordPress Plugin
GNU General Public License v2.0
7 stars 5 forks source link

Typo in action hook name #11

Open juliolopez78 opened 1 year ago

juliolopez78 commented 1 year ago

Hello!

Thank you for making this plugin, it adds much needed functionality to UM.

While working with it and trying to customize the form template, I noticed that the hook at the end of the form, has the wrong name. I'm assuming it should be um_raf_after_form instead of um_raf_before_form.

Thanks again for the great plugin.

juliolopez78 commented 1 year ago

Until a fix is implemented, here is a workaround:

// It's a bit hacky, but it works. the key is to set three functions to the 'um_raf_before_form' hook,
// each with increasing priority. This ensures that they fire in the correct order.

// In your theme's functions.php

/**
 * Take action before the opening <form> tag
 */
function doRafBeforeForm():void
{
    global $didRafBeforeForm;

    // When this fires the first time, $didRafBeforeForm should be null
    // When this fires the second time, $didRafBeforeForm should be true
    // Since this is the before action, we only do stuff when $didRafBeforeForm is null
    // otherwise, we move on
    if (is_null($didRafBeforeForm)) {
        // Do whatever you need to do before the form
    }
}

/**
 * Take action after the closing </form> tag
 */
function doRafAfterForm():void
{
    global $didRafBeforeForm;

    // When this fires the first time, $didRafBeforeForm should still be null
    // When this fires the second time, $didRafBeforeForm should still be true
    // Since this is the after action, we only do stuff when $didRafBeforeForm is true
    // otherwise, we move on
    if (is_bool($didRafBeforeForm) && $didRafBeforeForm) {
        // Do whatever you need to do after the form
    }
}

/**
 * Change the value of our flag in order to stop the before action from
 * firing twice and ensuring the after action fires
 */
function setDidRafBeforeForm():void
{
    global $didRafBeforeForm;

    // When this fires the first time, $didRafBeforeForm should still be null and we set it to true
    // When this fires the second time we do nothing.
    // Changint this variable is what will toggle the previous two actions
    if (is_null($didRafBeforeForm)) {
        $didRafBeforeForm = true;
    }
}

// Before the form, always with the lowest priority of the three hooks, i.e. 10
add_action('um_raf_before_form', 'doRafBeforeForm', 10, 0);

// After the form, always with a priority higher than the before hook, but lower than the last hook, i.e. 11
add_action('um_raf_before_form', 'doRafAfterForm', 11, 0);

// Toggles the before and after hooks, always with a priority higher than the previous two, i.e. 12
add_action('um_raf_before_form', 'setDidRafBeforeForm', 12, 0);
yaronguez commented 11 months ago

Thanks for the kind words! I haven't touched this project in several years so I'm not suited to make any updates. But feel free to submit a PR, thanks!