0

I want to call custom action, after a user is deleting his account. I'm using the premium theme wplms which is using buddypress for this stuff. After the submit button in the delete-account.php there is called the action bp_members_delete_account_after_submit:

               //...
        <div class="submit">
            <input type="submit" disabled="disabled" value="Konto löschen" id="delete-account-button" name="delete-account-button" />
        </div>

    <?php do_action( 'bp_members_delete_account_after_submit' ); ?>

According to this http://hookr.io/actions/bp_members_delete_account_after_submit/ I implemented the following code in my function.php:

function action_bp_members_delete_account_after_submit(  ) {
  do_action('myAction', 'arg1', 'arg2');
};
add_action( 'bp_members_delete_account_after_submit', 'action_bp_members_delete_account_after_submit', 10, 0 );

But nothing is happening. It seems like this function will never called? Did I something wrong?

1

It depends on what the function myAction() is doing.

Your order is this:

  1. pluging defines action hook with do_action( 'bp_members_delete_account_after_submit' );
  2. You hook a function on that with

    add_action( 'bp_members_delete_account_after_submit',
                'action_bp_members_delete_account_after_submit' );
    
  3. the function action_bp_members_delete_account_after_submit() is then adding a hook named 'myAction' and passing it two arguments as strings 'arg1' and 'arg2'.

But there is nothing to "happen" in the code above, unless you have a function hooked to myAction.

add_action( 'myAction', 'my_function', 10, 2 );

function my_function( $first_arg, $second_arg ) {
     //here, $first_arg would be literally equal to text 'arg1'
     // $second_arg would be literally equal to the text 'arg2'

     //you would do stuff here
}

Of course, you could skip some of that and run the code you need run inside the action_bp_members_delete_account_after_submit() function by making it:

function action_bp_members_delete_account_after_submit() {
    //you would do stuff here, 
    //no need to make another hook if you are not going to hook things to it
} 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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