0

I would like to run a PHP script "ONLY" when a user successfully fills out the WordPress Registration form and submits it as well as when a user updates their profile.

Here's what I have so far,

Registration
----------------
function soapConn() {
    if (!isset($_POST['submit-btn'])) {

    } else {
        // If pressed, run the script

        // Should I check for validation here? Such as if the inputs are empty?

        require_once locate_template('include/xxxx.php', true);
    }
}

add_action('registration_errors', 'soapConn');



Update user profile
-------------------

add_action( 'profile_update', 'my_profile_update', 10, 2 );

function my_profile_update( $user_id, $old_user_data ) {
     require_once locate_template('include/xxxx.php', true);
}

By doing it this way, it could save me the trouble from listening to the registration/profile update submit button in the PHP script file.

Can someone please assist and confirm that this is the right way to approach this problem?

Thank you for your time.

6
  • What do you mean by "ONLY"? Is that your way of saying "no Javascript"? Yes, you probably need some validation, and you probably need exit after the include. Have you tested this? What doesn't work?
    – s_ha_dum
    Commented Jan 14, 2014 at 19:32
  • Basically, the user's input data passes the default WP validation and once the form has been submitted by the user, run the xxx.php file. Does that make sense?
    – rolu
    Commented Jan 14, 2014 at 19:38
  • Makes sense. locate_template is only going to work with theme files though.
    – s_ha_dum
    Commented Jan 14, 2014 at 19:53
  • So, since ..include/xxx.php is a file I wrote, I should use require_once() instead of locate_template? Would something like this work since the file is located in the child theme? require_once( trailingslashit( get_stylesheet_directory() ) . 'include/xxx.php' );
    – rolu
    Commented Jan 14, 2014 at 20:03
  • If your file is in the theme directory locate_template will work. It will not work with files in plugin directories.
    – s_ha_dum
    Commented Jan 14, 2014 at 20:09

1 Answer 1

0

You would want to use the user_register and edit_user_profile_update actions. In this way you'll take care of both scenarios. Be careful. Both of these fire after the user information has already made it to the database.

4
  • So for the update user profile, Something like this would work I'm assuming? ` ` add_action( 'edit_user_profile_update', 'my_profile_update', 10, 2 ); function my_profile_update( $user_id ) { if ( current_user_can('edit_user',$user_id) ){ require_once locate_template('include/xxxx.php', true); } }
    – rolu
    Commented Jan 14, 2014 at 19:43
  • Yes. That would limit loading in that template for only admins. Commented Jan 14, 2014 at 19:49
  • So if I use personal_options_update, whenever a user updates their own profile/account, the PHP script will run?
    – rolu
    Commented Jan 14, 2014 at 19:52
  • Yes. That would only fire when a user updated their own profile. Commented Jan 14, 2014 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.