Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#33631 closed enhancement (fixed)

Add filter to prevent user creation during site creation

Reported by: mackensen Owned by: rachelbaker
Priority: normal Milestone: 4.5
Component: Networks and Sites Version: 4.4
Severity: normal Keywords: has-patch commit
Cc: Focuses: multisite

Description

We administer a multisite environment with external (LDAP) authentication configured. We do not allow local accounts. Our procedure when creating a new site is to add the soon-to-be-administrator from external authentication to the top-level site (if they did not already exist) before creating the site. If someone misses that first step, we wind up with an unwanted local account which then has to be fixed. What would be cool is a filter/hook in wp-admin/network/site-new.php that attaches to email_exists and lets you stop the site creation process if the user doesn't exist.

Attachments (4)

33631.diff​ (715 bytes ) - added by mackensen 11 years ago.
33631-fixed.diff​ (718 bytes ) - added by mackensen 11 years ago.
Corrected param type
33631.patch​ (757 bytes ) - added by rachelbaker 11 years ago.
Fixed spacing and added version to inline docs
33631.2.diff​ (787 bytes ) - added by jeremyfelt 11 years ago.

Download all attachments as: .zip

Change History (14)

#1 @SergeyBiryukov
11 years ago

  • Component Administration → Networks and Sites

A workaround:

function wp33631_check_for_existing_user_during_site_creation() {
	if ( ! isset( $_REQUEST['action'] ) || 'add-site' !== $_REQUEST['action'] ) {
		return;
	}

	if ( ! email_exists( $_POST['blog']['email'] ) ) {
		wp_die( 'User does not exist.' );
	}
}
add_action( 'admin_init', 'wp33631_check_for_existing_user_during_site_creation' );

#2 @mackensen
11 years ago

Working on this at WCUS Contributor Day. I've added a new action network_site_new_created_user_pending which fires immediately before user creation, so you could hook into it with a simple wp_die or whatever else you might want to do. I could see external auth attempting to auto provision the account.

#3 @rachelbaker
11 years ago

@mackensen Looks like you have wrong parameter type in the inline docs for the filter. Can you check it?

#4 @rachelbaker
11 years ago

  • Keywords has-patch needs-refresh dev-feedback added

@mackensen
11 years ago

Corrected param type

@rachelbaker
11 years ago

Fixed spacing and added version to inline docs

#5 @rachelbaker
11 years ago

  • Keywords commit added; needs-refresh dev-feedback removed

#6 @rachelbaker
11 years ago

  • Owner set to rachelbaker
  • Resolution → fixed
  • Status new → closed

In 35786:

Multisite: Add hook before a new user is created during the creation of a new site.

New network_site_new_created_user_pending action fires before a new user will be created via the network site-new.php page.

Props mackensen
Fixes #33631

#7 @jeremyfelt
11 years ago

  • Milestone Awaiting Review → 4.5
  • Resolution fixed
  • Status closed → reopened

We can probably tighten up the naming on this a bit to be more clear. Nothing is pending yet, as we still need to go through some other user checks to see if the email is valid before continuing. Using pre_ seems to make sense. I've added 33631.2.diff​ with this change.

Thoughts?

#8 @rachelbaker
11 years ago

In 35789:

Multisite: Clarify purpose of hook from [35786] and match our naming convention.

network_site_new_created_user_pending -> pre_network_site_new_created_user

See #33631

#9 @rachelbaker
11 years ago

  • Resolution → fixed
  • Status reopened → closed

#10 @DrewAPicture
11 years ago

In 36826:

Docs: Minorly improve the hook doc summary for the pre_network_site_new_created_user action, introduced in [35786].

See #33631. See #35986.

Note: See TracTickets for help on using tickets.