Jeremiah Sturgill

code etc.

WP Registration Code Plugin

This plugin allows new users to enter a registration code when they sign up to receive an elevated user role.

To load the plugin, copy the files to your plugin directory, activate it, and use the draw_registration_code_field() function in an action to insert the field into your registration form. Alternately, you can edit the registration form’s template to call the function directly. Details will differ depending on your theme. Additional options are available in the included config.php file.

Configuration options allow you to:

  • Set the field’s name and inline styles
  • Set the codes to be case sensitive or case insensitive
  • Decide whether the field’s value should be retained if the user fails to sign up correctly the first time (because their passwords don’t match, for example).

Configuration is handled by setting values in a PHP file, much like WordPress’s wp-config.php. Here is the plugin’s configuration file:

// Note: set up your registration codes by editing the array located in
// codes.php.

// Used to generate the field name, ID, label class, and holder class.
define( 'REG_CODE_FIELD_NAME', 'signup_code' );

// Set to TRUE to display the submitted value if the registration form
// hiccups for any reason (e.g., the passwords don't match, or a required
// form field was omitted).

// Set to false for case-sensitive registration codes.
// Case Sensitive: "THISCODE" is not the same as "ThisCode"
// Case Insensitive: "THISCODE" is exactly the same as "ThisCode"

// Setting this to TRUE means new users with valid codes will have only one role
// on the site: that defined by the code.  Setting it to false means the user
// will have two roles:  the default role, and the role assigned by the code.

// Styles here will be applied to the div that contains the reg field.
// Change to '' to omit styles.
define( 'REG_CODE_HOLDER_STYLES', 'clear:both;width:200px;padding-top:.5em;' );

// Setting this to true will automagically draw the field in the Buddypress 
// registration form.

define( 'BUDDYPRESS_REG_CODE_ACTION', 'bp_after_signup_profile_fields');

Registration codes are added or removed by editing a PHP array. Keys in the array are codes, and the corresponding value is the role the user is assigned. The default array looks like this:

// codes are keys in the array
// and roles are values
$code_to_role_map = array(
  'testcode' => 'editor',
  'testcode2' => 'contributor',

It comes with Buddypress integration out of the box, but placement options are limited when using Buddypress action hooks.

  • PHP
  • CSS
  • HTML
  • WordPress