matcher = $matcher; } /** * Check if email domain is allowed. * * @param string $user_email The email address to check. * @return bool True if allowed, false otherwise. * @since 1.2.0 */ public function is_domain_allowed( $user_email ) { if ( empty( $user_email ) || ! is_email( $user_email ) ) { return true; // Don't block invalid or empty emails here, let other filters handle it. } $options = get_option( 'aedr_settings', array() ); $allowed_domains = isset( $options['aedr_allowed_domains'] ) ? $options['aedr_allowed_domains'] : array(); $allowed_domains = array_filter( array_map( 'strtolower', array_map( 'trim', (array) $allowed_domains ) ) ); return $this->matcher->is_email_allowed( $user_email, $allowed_domains ); } /** * Validate email domain. * * Checks if the email domain is allowed based on plugin settings. * * @param WP_Error $errors The registration errors. * @param string $user_email The user's email. * * @return WP_Error The modified registration errors. * * @since 1.2.0 */ public function validate_email_domain( $errors, $user_email ) { if ( ! $this->is_domain_allowed( $user_email ) ) { $options = get_option( 'aedr_settings', array() ); $custom_error_message_allowed = isset( $options['aedr_custom_error_message_allowed'] ) && ! empty( $options['aedr_custom_error_message_allowed'] ) ? $options['aedr_custom_error_message_allowed'] : __( 'Your email domain is not allowed.', 'advanced-email-domain-restriction' ); $errors->add( self::ERROR_CODE, $custom_error_message_allowed ); } return $errors; } } }