Add field to user register form
-
I am adding a field in user register form.
add_action('register_form', array($this, 'add_field_to_register_form'));This works fine. However I am doing this in 3 plugins, so when the 3 plugins are activated the same field appears 3 times on the register form. I need the field which is the same in three plugins to be displayed just once. If it is displayed by one of the 3 plugins the other 2 plugins must not display it. I tried using this
if (false === has_action( 'register_form', 'add_field_to_register_form' )) { add_action('register_form', array($this, 'add_field_to_register_form')); }and this
if (false === has_action( 'register_form', array($this, 'add_field_to_register_form' ))) { add_action('register_form', array($this, 'add_field_to_register_form')); }and this
if (false === has_action( 'register_form', array(MyClassName::class, 'add_field_to_register_form' ))) { add_action('register_form', array($this, 'add_field_to_register_form')); }but they don’t work. It works like this
if (false === has_action( 'register_form')) { add_action('register_form', array($this, 'add_field_to_register_form')); }but this does not check the function name so it will work for any other action added to the register form.
Can you please assist? Thanks.
The topic ‘Add field to user register form’ is closed to new replies.