Skip to content

Instantly share code, notes, and snippets.

@supercleanse
Created February 5, 2013 05:23
Show Gist options
  • Save supercleanse/4712377 to your computer and use it in GitHub Desktop.
Save supercleanse/4712377 to your computer and use it in GitHub Desktop.
Shows how to add custom variables to a memberpress signup form.
<?php
/*
Plugin Name: MemberPress Custom Membership Signup
Plugin URI: http://memberpress.com
Description: Adds some custom fields to the MemberPress signup process
Version: 1.0.0
Author: MemberPress
Author URI: http://memberpress.com
Text Domain: memberpress
*/
if(!defined('ABSPATH')) {die('You are not allowed to call this page directly.');}
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if( is_plugin_active('memberpress/memberpress.php') ) {
class MemberpressCustomSignup {
public function __construct() {
$this->load_hooks();
}
public function load_hooks() {
add_action('mepr-user-signup-fields', array($this, 'display_signup_fields'));
add_filter('mepr-validate-signup', array($this, 'validate_signup_form'));
}
// This is where you put the html for the signup fields ...
// I prefer to just break out of the php block like so
public function display_signup_fields() {
?>
<div class="mepr_signup_table_row">
<label for="company"><?php _e('Company:'); ?></label>
<input type="text" name="company" id="company" value="" />
</div>
<?php
}
// This get's called after the post request ...
// the $error parameter is an array ... all you have to do to throw an error is
// add an error message to the $errors array and return it like so
public function validate_signup_form($errors) {
if(empty($_POST['company']))
$errors = __('Company can\'t be blank.');
return $errors;
}
}
// Load hooks, etc.
new MemberPressCustomSignup();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment