Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpmudev-sls/b5a9b2790acce8688cab6d2f32130089 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/b5a9b2790acce8688cab6d2f32130089 to your computer and use it in GitHub Desktop.
[Forminator] - Make user registration form respect the registration settings of the multisite network
<?php
/**
* Plugin Name: [Forminator] - Make user registration form respect the registration settings of the multisite network
* Plugin URI: https://wpmudev.com/
* Description: Forces the option set on the following path: Network Dashboard > Settings > Network Settings > Registration Settings
* Author: Glauber Silva @ WPMUDEV
* Author URI: https://wpmudev.com/
* Jira Task: SLS-308
* License: GPLv2 or later
*/
defined( 'ABSPATH' ) || exit;
/**
* Before creating a new site, check if the option chosen in
* "Network Dashboard > Settings > Network Settings > Registration Settings" allows this...
* Otherwise, it blocks the creation of the new site by Forminator.
*/
function wpmudev_intercept_multisite_validation( $validate, $custom_form, $submitted_data, $is_approve ) {
if ( is_multisite() ) {
/**
* Registration Options:
* 'none' => 'Registration is disabled'
* 'user' => 'User accounts may be registered'
* 'blog' => 'Logged in users may register new sites'
* 'all' => 'Both sites and user accounts can be registered'
*/
$registration = get_site_option( 'registration' );
if ( 'blog' !== $registration && 'all' !== $registration ) {
$custom_form->settings['site-registration'] = false; // Prevents new site registrations by Forminator.
}
}
return $validate;
}
add_filter( 'forminator_cform_user_registration_validation', 'wpmudev_intercept_multisite_validation', 0, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment