├── .gitignore ├── readme.txt ├── custom-multisite-signups-extras.php └── custom-multisite-signups.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Custom Multisite Signups === 2 | Contributors: afragen 3 | Requires at least: 3.4 4 | Tested up to: 3.9.1 5 | Plugin URI: https://github.com/afragen/custom-multisite-signups 6 | GitHub Plugin URI: https://github.com/afragen/custom-multisite-signups 7 | Stable tag: master 8 | Version: 0.2.0 9 | License: GPLv2 or later 10 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 | 12 | Framework for adding custom registration info during WP Multisite registration. 13 | 14 | == Description == 15 | 16 | This plugin adds first name, last name and sets display name during registration for WP Multisite site. Plenty of hooks are included so additional registration info and additional custom fields may be added. This can be added using another plugin. The custom-multisite-signups-extra.php file that is included here as an example. 17 | 18 | == Installation == 19 | 20 | This section describes how to install the plugin and get it working. 21 | 22 | 1. Upload `custom-multisite-signups` to the `/wp-content/plugins/` directory 23 | 1. Activate the plugin through the 'Plugins' menu in WordPress 24 | 25 | == Frequently Asked Questions == 26 | 27 | 28 | == Changelog == 29 | 30 | = 1.0.0 = 31 | * Initial commit 32 | 33 | -------------------------------------------------------------------------------- /custom-multisite-signups-extras.php: -------------------------------------------------------------------------------- 1 | Extra Field'; 18 | $extra_fields[] = ''; 19 | 20 | $html .= implode( "\n", $extra_fields ); 21 | echo $html; 22 | } 23 | 24 | public function extra_fields_selectors( $selectors ) { 25 | $selectors .= ', .mu_register #extra_field1'; 26 | return $selectors; 27 | } 28 | 29 | public function extra_fields_css( $css ) { 30 | $css .= ' /* CSS comment */ '; 31 | return $css; 32 | } 33 | 34 | public function validate_user_signup( $result ) { 35 | if ( empty( $_POST['extra_field1'] ) ) { 36 | $result['errors']->add( 'last_name', __( 'You must include an extra field.' ) ); 37 | echo '
', $result['errors']->get_error_message('extra_field1'), '
'; 38 | } 39 | 40 | return $result; 41 | } 42 | 43 | public function cms_extra_signup_meta() { 44 | return array( 45 | 'extra_field1' => sanitize_text_field( $_POST['extra_field1'] ), 46 | ); 47 | } 48 | 49 | public function show_extra_profile_fields( $user ) { 50 | 51 | $html[] = '', $result['errors']->get_error_message('first_name'), '
'; 108 | } 109 | 110 | if ( empty( $_POST['last_name'] ) ) { 111 | $result['errors']->add( 'last_name', __( 'You must include a last name.' ) ); 112 | echo '', $result['errors']->get_error_message('last_name'), '
'; 113 | } 114 | 115 | if ( preg_match( '/[^-a-zA-Z]/', $_POST['first_name'] ) or preg_match( '/[^-a-zA-Z]/', $_POST['last_name'] ) ) { 116 | $result['errors']->add( 'name', __( 'Names may only contain letters or hyphens.' ) ); 117 | echo '', $result['errors']->get_error_message('name'), '
'; 118 | } 119 | 120 | if ( has_filter( 'cms_wpmu_validate_user_signup' ) ) { 121 | return apply_filters( 'cms_wpmu_validate_user_signup', $result ); 122 | } else { 123 | return $result; 124 | } 125 | } 126 | 127 | /** 128 | * Add values to wp_signups table 129 | * 130 | * @param array 131 | * @return array 132 | * @filter hook returns array of key, value pairs 133 | */ 134 | public function _add_signup_meta( $meta = array() ) { 135 | 136 | $fname = sanitize_text_field( $this->ucname( $_POST['first_name'] ) ); 137 | $lname = sanitize_text_field( $this->ucname( $_POST['last_name'] ) ); 138 | 139 | // create an array of custom meta fields 140 | $meta['custom_usermeta'] = array( 141 | 'first_name' => $fname, 142 | 'last_name' => $lname, 143 | 'display_name' => $fname . ' ' . $lname, 144 | ); 145 | if ( has_filter( 'cms_extra_signup_meta') ) 146 | $meta = $meta['custom_usermeta'] + apply_filters( 'cms_extra_signup_meta', $meta ); 147 | 148 | return $meta; 149 | 150 | } 151 | 152 | /** 153 | * Upon activation loops through wp_signups data to add to user_meta 154 | * 155 | * @param ($meta) array of key,value pairs. 156 | */ 157 | public function insert_meta_on_activation( $user_id, $email, $meta ) { 158 | 159 | // loop through array of custom meta fields 160 | foreach ( $meta as $key => $value ) { 161 | // and set each one as a meta field 162 | update_user_meta( $user_id, $key, $value ); 163 | } 164 | wp_update_user( array( 165 | 'ID' => $user_id, 166 | 'display_name' => $meta['display_name'], 167 | ) 168 | ); 169 | 170 | } 171 | 172 | /** 173 | * Add additional custom field to profile page 174 | * 175 | * @param - $user 176 | * @filter hook returns html 177 | */ 178 | public function show_extra_profile_fields ( $user ) { 179 | 180 | echo "\n", '