• After this filter hook in wp_insert_user:
    $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, $update ? (int) $ID : null );

    add_action('wp_pre_insert_user_data', $data); is needed to add rules regarding force strong password or restrict display name etc

    Also, wp_update_user needs same add_action hook like above reason.

    Thank you for your supports always.

    • This topic was modified 4 years, 11 months ago by stokim.
    • This topic was modified 4 years, 11 months ago by stokim.
    • This topic was modified 4 years, 11 months ago by stokim.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    That would not work, not with the same name. Actions and filters are actually different forms of the same thing, so you can’t give them the same names, because both would trigger on either.

    Actions are just a subset of filters, basically.

    Also, that is far too late in the process to be attempting to enforce things like strong passwords or display names or what have you. When wp_insert_user is called, then a user really has to be inserted. If you want to enforce a rule, then you should catch it at the point where the data is collected and you have a chance to return it back to the interface, to tell the user that the rule is not satisfied.

    Thread Starter stokim

    (@stokim)

    @otto42 Thank you so much for your reply.
    You’re right, I agree with you that it would be better to enforce a rule at the point of data collected.
    However, if we run Buddypress with a theme, they add and edit member’s password, display name, and email address separately. If we enforce strong password, limited display name, and limited email domain on register and settings, we have to add rules separately on theme’s function and plugin’s function.
    If WordPress has an action filter at the first of line,
    do_action('wp_pre_insert_user', $data);
    We can just add rules with WP_Error class once.
    Like above, wp_update_user,
    do_action('wp_pre_update_user', $data);
    In terms of consistency, we don’t need to consider the way of theme and plugins.
    Thank you for your consideration again and have a wonderful day ??

    P.S. Thank you for letting me know the concept of filters. That sort of tips helps a lot for me ??

    Best regards,
    Jen

    • This reply was modified 4 years, 11 months ago by stokim.
    • This reply was modified 4 years, 11 months ago by stokim.
    • This reply was modified 4 years, 11 months ago by stokim.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add action filter into wp_insert_user and wp_update_user’ is closed to new replies.