0

My goal is to change the registration email sent to new users. However, overriding the function responsible for sending the email does not work..

The relevant file in the parent theme folder looks like this (I use Eduma theme):

eduma/inc/register-functions.php:

class ThimEdumaRegisterFunction {
    protected static $_instance;
    protected $action_ajax = array();

    protected function __construct() {
        $this->addHook();
    }

    protected function addHook() {
       // ...

       add_filter( 'password_change_email', array( $this, 'message_when_user_register_auto_login' ), 999999, 1 );
    }

    // ...

    public function message_when_user_register_auto_login( $objectEmail = array() ) {
        if ( get_theme_mod( 'thim_auto_login', true ) ) {
            $objectEmail['subject'] = 'Welcome to [%s]';
            $objectEmail['message'] = sprintf(
                'OLD EMAIL TEXT' 
            );

            return $objectEmail;
        }

    }
}

My attempt to override:

eduma-child/functions.php:

/* Override User Registration Email */

function remove_password_change_email_filter(){
    remove_filter('password_change_email', array( $this, 'message_when_user_register_auto_login' ), 999999, 1);
}
add_action( 'after_setup_theme', 'remove_password_change_email_filter' );

function wk_registration_email($objectEmail = array()) {
    if ( get_theme_mod( 'thim_auto_login', true ) ) {
        $objectEmail['subject'] = '[%s] - Your registration';
        $objectEmail['message'] = sprintf(
            'NEW EMAIL TEXT' 
        );

        return $objectEmail;
    }
}
add_filter( 'password_change_email', array( $this, 'wk_registration_email' ), 9999999);

This piece of code breaks my WordPress website. How do I need to adapt the code?

Your Answer

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

Browse other questions tagged or ask your own question.