Skip to content

Hooks and API

Technical reference for extending Restrict Email Domain for WordPress. All classes use the singleton pattern and are prefixed REDW_.

REDW_VERSION // Plugin version
REDW_PLUGIN_DIR // Plugin directory path
REDW_PLUGIN_URL // Plugin URL
REDW_PLUGIN_BASENAME // Plugin basename
REDW_STORE_URL // EDD store URL
REDW_ITEM_ID // EDD item ID
REDW_ITEM_NAME // EDD item name
Class File Responsibility
REDW_Settings includes/class-settings.php Load, save, and sanitize settings and domain lists
REDW_Validator includes/class-validator.php Domain matching, front-end AJAX validation, notifications
REDW_Logger includes/class-logger.php Log writes, stats, CSV export, cleanup
REDW_Import_Export includes/class-import-export.php Import/export of settings and domain lists
REDW_Admin admin/class-admin.php Admin screens and admin AJAX handlers
$settings = REDW_Settings::get_instance();
$value = $settings->get( 'key', 'default' );
$settings->set( 'key', 'value' );
$all = $settings->get_all();
$settings->update_all( array( 'key' => 'value' ) );
$allowed = $settings->get_allowed_domains(); // array
$banned = $settings->get_banned_domains(); // array
$emails = $settings->get_whitelist_emails(); // array
$json = $settings->export_settings();
$result = $settings->import_settings( $json_string );

Settings keys (stored in the redw_settings option):

Key Type Default
allowed_domains string ‘’
banned_domains string ‘’
error_message string Registration is restricted for this domain or email.
enable_logging bool true
log_retention_days int 30
enable_real_time_validation bool true
whitelist_emails string ‘’
notification_email string admin email
enable_notifications bool false
case_sensitive bool false
strict_subdomain_matching bool false
delete_data_on_uninstall bool false
$validator = REDW_Validator::get_instance();
$is_allowed = $validator->is_email_allowed( 'user@example.com' ); // bool
$is_allowed = $validator->validate_and_log( $email, 'my_source' ); // logs + notifies if blocked
$message = $validator->get_validation_error( 'user@blocked.com' ); // string

Matching order inside is_email_allowed(): email whitelist, then allowed domains (if any), then banned domains (if any), else allow.

$logger = REDW_Logger::get_instance();
$logger->log_blocked_attempt( $email, $source );
$logs = $logger->get_logs( array( 'limit' => 50, 'offset' => 0, 'source' => '', 'domain' => '', 'date_from' => '', 'date_to' => '' ) );
$stats = $logger->get_stats( 30 ); // total_blocked, by_source, top_domains, daily_blocked
$count = $logger->get_log_count( $args );
$csv = $logger->export_logs( $args );
$logger->cleanup_old_logs();
Option Purpose
redw_settings All plugin settings (array)
redw_license_key License key
redw_license_status License status
redw_license_data License data from the EDD API
redw_version Installed version
CREATE TABLE {prefix}redw_logs (
id mediumint(9) NOT NULL AUTO_INCREMENT,
email varchar(100) NOT NULL,
domain varchar(100) NOT NULL,
source varchar(50) NOT NULL,
ip_address varchar(45) NOT NULL,
user_agent text,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY email (email),
KEY domain (domain),
KEY source (source),
KEY created_at (created_at)
);

The plugin hooks WordPress and integration registration flows. Core hooks: registration_errors (priority 20) and wpmu_validate_user_signup (priority 20). See Integrations for the per-plugin hooks and log source values.

redw_cleanup_logs runs daily and deletes log rows older than log_retention_days.

Front-end (nonce redw_ajax_nonce):

  • redw_validate_email (and nopriv variant) - real-time email validation.

Admin (nonce redw_admin_nonce, capability manage_options):

  • redw_save_settings
  • redw_test_email
  • redw_validate_domains
  • redw_check_config
  • redw_get_integration_status
  • redw_cleanup_logs
  • redw_export_settings, redw_import_settings
  • redw_export_logs
  • redw_export_domains, redw_import_domains
  • redw_quick_import_disposable

Front-end validation response shape:

{ "success": true, "data": { "message": "Email domain is allowed" } }
{ "success": false, "data": { "message": "Registration is restricted for this domain or email." } }

To cover a plugin that bypasses standard WordPress hooks, add a class that runs only when the target plugin is present, validates through REDW_Validator, and exposes get_integration_status().

class REDW_Custom_Plugin {
private static $instance = null;
private $validator;
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
if ( ! class_exists( 'Custom_Plugin_Class' ) ) {
return;
}
$this->validator = REDW_Validator::get_instance();
add_filter( 'custom_plugin_registration_errors', array( $this, 'validate_registration' ), 10, 2 );
}
public function validate_registration( $errors, $email ) {
if ( ! $this->validator->validate_and_log( $email, 'custom_plugin' ) ) {
$errors->add( 'email_domain_restricted', $this->validator->get_validation_error( $email ) );
}
return $errors;
}
public function get_integration_status() {
return array(
'name' => 'Custom Plugin',
'active' => class_exists( 'Custom_Plugin_Class' ),
'version' => defined( 'CUSTOM_PLUGIN_VERSION' ) ? CUSTOM_PLUGIN_VERSION : null,
'supported_features' => array( 'Registration Forms' ),
);
}
}

Load the class (for example on plugins_loaded) and add its class name to RestrictEmailDomainWP::get_integrations_status() so it appears on the Tools tab.