• Resolved David Bee

    (@davidbawiec)


    Hi!

    First off, I LOVE Ulitmate Member. You created a really fantastic work of art.

    Having said that, unfortunately, I have to report a bug: UM breaks any custom forms and instead re-directs them to the homepage.
    This is the same bug that was reported over a year ago here: https://www.ads-software.com/support/topic/submitting-front-end-form-from-custom-plugin-as-a-member-not-admin/

    I have a simple form

    <form action="https://local.dev.com/wp-admin/admin-post.php" method="post">
    <input type="radio" name="app_id" value="652" checked="checked"> Appointment 1<br>
    <input type="radio" name="app_id" value="451"> Appointment 2<br>
    <input type="hidden" name="action" value="app_payment_id_selection_form">
    <input type="submit" value="Pay for selected appointment">
    </form>

    To then process the form, I use:
    add_action( 'admin_post_app_payment_id_selection_form', 'save_requested_app_id_to_user_meta' );

    In save_requested_app_id_to_user_meta() I process the form, save any necessary information to the database, and finally redirect the users to a different page. This works like a charm. However, the moment I activate Ultimate member, things break. Administrators are still able to fully process the form without issues. All other users, however, get redirected to the homepage instead. The form never processes and the action hooks never even get a chance to trigger.

    Please help!
    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mykyta Synelnikov

    (@nsinelnikov)

    Hi @davidbawiec,

    Do you plan to submit frontend form? I recommend don’t use admin-post.php file as main handler with ‘admin_post_{action_name}’ for frontend forms.

    Thanks!

    Thread Starter David Bee

    (@davidbawiec)

    Hi @nsinelnikov,

    Thanks for the reply. As much as your suggested workaround may work for my own forms, I see four different third-party plugins on our site that hook into admin_post_{action_name}. So your workaround won’t solve the issue. I much prefer we find a solution to how/when UM creates the redirect to make sure it doesn’t interfere with these plugins (and so many more which have been discussed on the forum here).

    admin_post_{action_name} is the basic form equivalent to how you can hook into wp_ajax_{action_name} for Ajax requests. And just like there’s a wp_ajax_nopriv_{action_name} that triggers for non-logged in users, admin_post has an equivalent as well: admin_post_nopriv_{action_name}. In fact UM hooks into wp_ajax_nopriv_{action_name} on multiple occasions. So you can see how it can be used as part of frontend forms. I can see how the word ‘admin’ makes it confusing though. In this case, admin should be thought of more administrative rather than an administrator.

    I skimmed through the code and it looks like wp-admin/admin-post.php doesn’t get to processing the POST action hooks till after wp-load.php and wp-admin/includes/admin.php are loaded. Which (if I’m not mistaken) means that UM triggers its redirect before we get to the hooks?

    Plugin Author Mykyta Synelnikov

    (@nsinelnikov)

    Hi @davidbawiec

    Could you check this option for the user’s role https://www.screencast.com/t/KmWSDUqFZ
    All users who don’t have an ability to visit wp-admin haven’t ability to post forms via wp-admin “admin_post”. “admin_post_nopriv” works properly.

    But we will fix this issue in the next Ultimate Member version.

    Let me know if the capability works for you.
    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘UM breaks custom forms’ is closed to new replies.